本文共 1344 字,大约阅读时间需要 4 分钟。
所有单位使用单位px
0.美术切图按固定比例。如1080*1920
一:XML配置
1.根目录设置固定宽高(美术切图比例)。如:1080*1920
2.图片引用使用src,防止自动拉伸。如:android:src = "@drawable/loading_bg"
3. 图片宽高使用切图原始大小,如:loading_bg 的尺寸为1080*1920
例:
android:layout_width="1080px"
android:layout_height="1920px"
android:src="@drawable/loading_bg"
二:Activity控制根据屏幕大小缩放
getWindow().getDecorView().setBackgroundColor(Color.BLACK);
WindowManager wm = (WindowManager) FolderListActivity.this.getSystemService(Context.WINDOW_SERVICE);int width = wm.getDefaultDisplay().getWidth();int height = wm.getDefaultDisplay().getHeight();float scaleNum = (float)height/1920f;rootLayout.setPivotY(0);rootLayout.setScaleY(scaleNum);rootLayout.setScaleX(scaleNum);if (scaleNum * 1080 < width) { int offsetX = (int)((width - scaleNum * 1080) / 2); ViewGroup.LayoutParams params = rootLayout.getLayoutParams(); if (params instanceof FrameLayout.LayoutParams) { ((FrameLayout.LayoutParams)params).setMargins(offsetX, 0, 0, 0); } if (params instanceof LinearLayout.LayoutParams) { ((LinearLayout.LayoutParams)params).setMargins(offsetX, 0, 0, 0); } if (params instanceof RelativeLayout.LayoutParams) { ((RelativeLayout.LayoutParams)params).setMargins(offsetX, 0, 0, 0); } rootLayout.setLayoutParams(params);}Log.e("当前手机分辨率:","宽:"+width+"..高:"+height);Log.e("当前手机分辨率:","缩放系数:"+scaleNum);
三:颤抖吧,凡人!!!
xml布局样例:
转载地址:http://tpmwb.baihongyu.com/