这也是android适配的一种方法 :
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) {
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(btn_back.getLayoutParams());
lp.setMargins(0, 10, 0, 0);
btn_back.setLayoutParams(lp);
}
简洁的工具方法:
public static void setMargins (View v, int l, int t, int r, int b) {
if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
p.setMargins(l, t, r, b);
v.requestLayout();
}
}
本文介绍了一种针对Android应用的视图适配方法,通过检查设备的API级别,动态调整按钮的边距,确保应用在不同设备上的显示效果一致。提供了一个简洁的工具方法setMargins,用于设置View的边距。
519

被折叠的 条评论
为什么被折叠?



