【问题标题】:Android Layout 3 Items With Different Widths In Same LineAndroid Layout 3 同一行不同宽度的项目
【发布时间】:2017-01-14 22:46:08
【问题描述】:

我想知道如何将 3 个不同宽度的元素放在同一行中?

如下图

LinearLayout,其中包含水平方向(父级), Textview(50% width-align left)ImageView(25% width-align right)Textview(25% width-align right)都在同一行?

请帮忙。

【问题讨论】:

  • 您是否检查了属性android:layout_weight 的子视图?

标签: android layout android-linearlayout


【解决方案1】:

您可以使用LinearLayout 与权重

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_landing"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.50"
        android:text="1" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.25"
        android:text="2" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.25"
        android:text="3" />
</LinearLayout>

或者

您可以使用PercentRelativeLayout 看到这个answer

【讨论】:

  • @joelj 欢迎您,如果这也有助于您投票:)
【解决方案2】:

您可以在水平方向的 LinearLayout 内使用 3 个具有各自权重的 RelativeLayout。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-08-24
    • 2013-08-01
    • 2022-08-23
    • 2018-02-22
    • 2016-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多