15. Screen Fit

Source: Internet
Author: User

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?
    • Picture adaptation
It is not very common to put a set of graphs in each drawable, but it can lead to a large volume of software.
    • Layout adaptation
Not very common, layout-800x480 is specially adapted for 480*800 screens
    • Size adaptation
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
    • Weight Matching
Android:weightsum= "3"
    • Code adaptation
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
  
 
  1. public class DensityUtils {
  2. /**
  3. * dp转px
  4. */
  5. public static int dp2px(Context ctx, float dp) {
  6. Span class= "KWD" >float density = CTX getresources (). getdisplaymetrics (). density ;//get screen pixel density
  7. int px = (int) (dp * density + 0.5f);// 4.9->5 4.4->4
  8. return px;
  9. }
  10. public static float px2dp(Context ctx, int px) {
  11. float density = ctx.getResources().getDisplayMetrics().density;
  12. float dp = px / density;
  13. return dp;
  14. }
  15. }
2. Boot page red dot (DP)
  
 
  1. <View
  2. android:id="@+id/view_red_point"
  3. android:layout_width="10dp"
  4. android:layout_height="10dp"
  5. android:background="@drawable/shape_point_red" />
Little Gray Dot
  
 
  1. // 初始化引导页的小圆点
  2. Span class= "KWD" >for ( int i = 0 I < Mimageids length I ++) {
  3. View point = new View(this);
  4. point.setBackgroundResource(R.drawable.shape_point_gray);// 设置引导页默认圆点
  5. This is a pixel DX, converted into DP
  6. LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
  7. Span class= "Typ" >densityutils dp2px ( this Span class= "lit" >10 densityutils dp2px ( this Span class= "lit" >10
  8. if (i > 0) {
  9. params.leftMargin = DensityUtils.dp2px(this, 10);// 设置圆点间隔
  10. }
  11. point.setLayoutParams(params);// 设置圆点的大小
  12. llPointGroup.addView(point);// 将圆点添加给线性布局
  13. }

3. Main Page: Modify in code
  
 
  1. public void onCreate(Bundle savedInstanceState) {
  2. super.onCreate(savedInstanceState);
  3. requestWindowFeature(Window.FEATURE_NO_TITLE);
  4. setContentView(R.layout.activity_main);
  5. setBehindContentView(R.layout.left_menu);// 设置侧边栏
  6. SlidingMenu slidingMenu = getSlidingMenu();// 获取侧边栏对象
  7. slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);// 设置全屏触摸
  8. int width = getWindowManager().getDefaultDisplay().getWidth();// 获取屏幕宽度
  9. slidingMenu.setBehindOffset(width * 200 / 320);// 设置预留屏幕的宽度,按比例
  10. initFragment();
  11. }
Made by the artist





From for notes (Wiz)

15. Screen Fit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.