RelativeLayout布局设置
1
2
3
4
5
6
7
8int screenWidth = ScreenUtils.getScreenWidth(getBaseContext());//获取屏幕高度
int onew = screenWidth / 5;
int s1 = onew / 3;
int magnification = ScreenUtils.dip2px(getBaseContext(), 50) / 50;//获取屏幕高度并算出dp和px的倍数
ViewGroup.LayoutParams layoutParams = tongzhi_dot.getLayoutParams();
RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams2.setMargins(screenWidth - s1 - 15, magnification * 10, s1, 35 * magnification);//4个参数按顺序分别是左上右下
tongzhi_dot.setLayoutParams(layoutParams2); //tongzhi_dot 一个View的布局IDLinearLayout
1
2
3LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(10, 20, 30, 40);
imageView.setLayoutParams(lp);LinearLayout 设置高宽
1
2LinearLayout box = (LinearLayout) layout.findViewById(R.id.dialog_liner_box);
box.setLayoutParams(new LinearLayout.LayoutParams((int) (ScreenUtils.getScreenWidth(context) * 0.8), ViewGroup.LayoutParams.WRAP_CONTENT));
ScreenUtils 分享
1 | import android.app.Activity; |