Squ*_*les 2 android android-layout
我有一个在xml中定义了ImageButton的相对布局。图片按钮的属性为android:layout_marginBottom =“ 25dp”。
是否可以在运行时更改此属性,我想根据屏幕尺寸移动按钮。我以为会有ImageButton.setMarginBottom方法,但似乎没有。另一个与Android不一致的地方。
尝试这个:
ImageButton imgBtn = (ImageButton)findViewById(R.id.img_btn);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imgBtn.getLayoutParams();
params.setMargins(0, 0, 0, 25); //bottom margin is 25 here (change it as u wish)
imgBtn.setLayoutParams(params);
Run Code Online (Sandbox Code Playgroud)