java - Android布局边距使宽度为0

标签 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" />

最佳答案

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/

相关文章:

java - IntelliJ 运行单个 Java 文件

android - 如何更改 ExpandableListView 组指示器位置?

android - 如何在 Android 中将 TextView 转换为 EditText?

android - 在 Listview 中使用 ViewPager 时不会调用 OnItemClickListener

java - 通过交叉连接进行 UDP 广播

java - 如何使用java获取http参数?

JAVA类转成xml文件

android - 为安卓手机创建应用锁

android - 如果离线,使用 Picasso 从磁盘缓存加载图像

相当于 textCapSentences 的 android TextView