【问题标题】:Android ImageButton not aligned with EditText and ButtonAndroid ImageButton 未与 EditText 和 Button 对齐
【发布时间】:2011-07-14 08:36:01
【问题描述】:

我目前在我的 layout.xml 中有这个

        <EditText android:id="@+id/body" android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:layout_weight="1"
            android:hint="Type to compose" />
        <ImageButton android:id="@+id/attach"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:src="@drawable/attach_photo" />
        <Button android:id="@+id/send" android:text="@string/send"
            android:layout_width="wrap_content" android:layout_height="wrap_content" />
    </LinearLayout>

我面临的问题是 ImageButton 的顶部没有像 Button 和 EditText 那样对齐。其他 2 个很好地填充了高度,但 ImageButton 似乎向上伸出。有什么想法吗?

【问题讨论】:

  • 添加内边距也不会使按钮移动。

标签: android android-linearlayout imagebutton


【解决方案1】:

尝试使用RelativeLayout。您可以将视图与父级或任何其他view 的侧面、顶部和底部对齐。

使用android:layout_alignParentTop="true" 或类似名称。

您可以在RelativeLayout 中使用大量 xml 命令。

【讨论】:

    【解决方案2】:

    您还可以在线性布局的子级上设置布局权重属性。您可以设置edittext、imagebutton和button的权重,这将使您的组件在屏幕上对齐。

    【讨论】:

    • 这只会影响小部件的大小,不会影响对齐方式。
    猜你喜欢
    • 1970-01-01
    • 2014-02-18
    • 1970-01-01
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-28
    • 1970-01-01
    相关资源
    最近更新 更多