当我尝试在 Java 中更改某些内容的左边距或右边距时,它不起作用。相反,它将按钮缩小到宽度为 0dp 的位置。 这是我的代码:
RelativeLayout.LayoutParams TwoPos = (RelativeLayout.LayoutParams) ezONEaONE.getLayoutParams();
TwoPos.bottomMargin = 515;
TwoPos.leftMargin = 50;
ezONEaONE.setLayoutParams(TwoPos);
我在布局中的按钮:
<Button
android:text="@string/ez1a1"
android:id="@+id/ez1a1"
android:background="@android:color/holo_orange_dark"
android:textSize="24sp"
tools:ignore="Deprecated,NewApi,RtlHardcoded,TextViewEdits"
android:onClick="Ez1A1"
android:minWidth="88dp"
android:minHeight="46dp"
android:autoText="false"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginBottom="10dp"
android:typeface="serif"
android:layout_above="@+id/ez1N1" />
最佳答案
Button ezOneaOne = (Button) findViewById(R.id.ezOneaOneIDName);
RelativeLayout.LayoutParams TwoPos = (RelativeLayout.LayoutParams) ezONEaOne.getLayoutParams();
TwoPos.setMargins(50, 0, 0, 515); //left, top, right, bottom
ezOneaOne.setLayoutParams(TwoPos);
您可能必须将 dp
放在末尾。抱歉,如果它不起作用。
关于java - Android布局边距使宽度为0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43403030/