2017-04-13 24 views
2

当我尝试在Java中更改左右边距时,它不起作用。相反,它将按钮缩小到宽度为0dp的位置。 这里是我的代码:Android布局边距制作宽度为0

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" /> 
+0

你可以分享你的布局文件? – azizbekian

+0

我添加了按钮 – Ebaad

回答

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末。很抱歉,如果它不起作用。

+0

的布局文件我已经在它的末尾有dp,即使我没有它也会自动添加dp tp它。 – Ebaad

+0

哦,所以你已经尝试过了。 –

+0

我曾尝试过,它做了同样的事情 – Ebaad

0

删除此:

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

从我的代码或我的问题? – Ebaad

+0

对于你的问题,朋友。 –