Android布局边距使宽度为0

时间:2017-04-13 23:07:33

标签: java android android-layout android-relativelayout

当我试图改变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" />

2 个答案:

答案 0 :(得分:0)

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放在最后。对不起,如果它不起作用。

答案 1 :(得分:0)

删除它:

android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignRight="@+id/ez1N1"
android:layout_alignEnd="@+id/ez1N1"