Screen Fit
- Mainstream screen: 1280*720, follow the principle: no absolutelayout (absolute layout), multi-use relative layout & linear layout (weight), to use DP, without PX
- Post-development, test on different resolutions screen (480*800,1920*1080), if not too big problem (affect normal use), you can go online
What if the problem is measured later?
It is not very common to put a set of graphs in each drawable, but it can lead to a large volume of software.
Not very common, layout-800x480 is specially adapted for 480*800 screens
DP and px Relationships: DP = px/device density
float density = getresources (). Getdisplaymetrics (). density;SYSTEM.OUT.PRINTLN ("Device density:" + density);
320*240 (0.75), 480*320 (1), 480*800 (1.5), 1280*720 (2)
Values->dimens.xml values-1280x720
Android:weightsum= "3"
Get screen width height, dynamic calculation control size in the Smart Beijing Guide page below the dot write dead, sidebar also in the big screen will pull out very long, now modify: 1. Create a tool class
public class DensityUtils {
/**
* dp转px
*/
public static int dp2px(Context ctx, float dp) {
Span class= "KWD" >float density = CTX getresources (). getdisplaymetrics (). density ;//get screen pixel density
int px = (int) (dp * density + 0.5f);// 4.9->5 4.4->4
return px;
}
public static float px2dp(Context ctx, int px) {
float density = ctx.getResources().getDisplayMetrics().density;
float dp = px / density;
return dp;
}
}
2. Boot page red dot (DP)
<View
android:id="@+id/view_red_point"
android:layout_width="10dp"
android:layout_height="10dp"
android:background="@drawable/shape_point_red" />
Little Gray Dot
// 初始化引导页的小圆点
Span class= "KWD" >for ( int i = 0 I < Mimageids length I ++) {
View point = new View(this);
point.setBackgroundResource(R.drawable.shape_point_gray);// 设置引导页默认圆点
- This is a pixel DX, converted into DP
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
Span class= "Typ" >densityutils dp2px ( this Span class= "lit" >10 densityutils dp2px ( this Span class= "lit" >10
if (i > 0) {
params.leftMargin = DensityUtils.dp2px(this, 10);// 设置圆点间隔
}
point.setLayoutParams(params);// 设置圆点的大小
llPointGroup.addView(point);// 将圆点添加给线性布局
}
3. Main Page: Modify in code
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
setBehindContentView(R.layout.left_menu);// 设置侧边栏
SlidingMenu slidingMenu = getSlidingMenu();// 获取侧边栏对象
slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);// 设置全屏触摸
int width = getWindowManager().getDefaultDisplay().getWidth();// 获取屏幕宽度
slidingMenu.setBehindOffset(width * 200 / 320);// 设置预留屏幕的宽度,按比例
initFragment();
}
Made by the artist
From for notes (Wiz)
15. Screen Fit