【问题标题】:Align ImageButton right inside Tablerow在 Tablerow 内对齐 ImageButton
【发布时间】:2019-11-04 12:22:54
【问题描述】:

我希望我的图像按钮右对齐,但即使gravity="right" 也可以看到它的左对齐。这是我的文件:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:app="http://schemas.android.com/apk/res-auto"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:orientation="horizontal"
 >

<TableRow android:layout_height="20dp">


    <ImageButton
        android:id="@+id/imageButton2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right"
        android:backgroundTint="@android:color/transparent"
        android:graviy="right"
        app:srcCompat="@drawable/ic_person_black_24dp" />
</TableRow>

</TableLayout>

如何正确对齐我的图像按钮?我虽然gravity="right" 会解决问题吗?我尝试了 layout_gravity 和重力。两者都不起作用

【问题讨论】:

    标签: android android-layout android-imagebutton androiddesignsupport android-layout-editor


    【解决方案1】:

    首先,你有graviy 而不是gravity
    gravity 属性指定“我的孩子在我体内如何排列” - 例如。 TextView 中的文本,Layout 中的视图。 layout_gravity 告诉父母“我想如何定位”。 并非所有布局都尊重其孩子的layout_gravity,在这种情况下,将gravity="end" 设置为您的TableRow 作品。 您可以从ImageButton 中删除gravitylayout_gravity

    【讨论】:

      猜你喜欢
      • 2011-04-21
      • 2011-09-16
      • 2014-10-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多