从右到左而不是从左到右的开始按钮

时间:2019-10-17 07:06:42

标签: android android-layout android-button material-components material-components-android

我正在尝试使Button中的LinearLayout从右侧开始,并从{的右侧设置Button 5dp {1}},其中LinearLayout显示在按钮的左侧。当前,它仅允许从线性布局的“左侧”边缘设置按钮。我尝试了各种方式,但似乎没有任何效果。

TextView

5 个答案:

答案 0 :(得分:1)

您可以将android:layout_weight=1参数设置为TextView

答案 1 :(得分:1)

在XML中使用layoutGravity标签作为(右,左)

答案 2 :(得分:1)

您必须在布局中添加android:gravity="right"。因此,所有内部小部件都将从右到左设置。如下所示。

<LinearLayout
                android:id="@+id/remote_button_layout"
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:layout_marginStart="20dp"
                android:layout_marginEnd="20dp"
                android:layout_marginTop="30dp"
                android:gravity="right
                android:background="@drawable/btn_remote_button"
                android:orientation="horizontal">

答案 3 :(得分:1)

使用此android:layout_gravity作为(左,右),您可以引用此链接What is the difference between gravity and layout_gravity in Android?

答案 4 :(得分:1)

根据您的情况,您只需更改android:gravity="right"中的LinearLayout属性即可。

  <LinearLayout
      android:gravity="right"

之前:
enter image description here 之后:
enter image description here

您还可以考虑使用MaterialButton添加文字和图标来做其他事情。

    <com.google.android.material.button.MaterialButton
        style="@style/Widget.MaterialComponents.Button.Icon"
        app:icon="@drawable/..."
        app:iconGravity="end"
        android:text="@string/..."/>

enter image description here