【问题标题】:What is the standard layout for a three-column List Component in Android?Android中三列List组件的标准布局是什么?
【发布时间】:2016-12-06 22:20:05
【问题描述】:

我正在尝试在具有图像、线性布局中的两个文本视图和另一个图像的 Android 应用程序中组合一个视图。它的样式类似于列表视图“单元格”,让我想知道创建 Android 标准列表项组件的最佳方法是什么。在讨论这些组件的外观时,Android 样式指南非常具体,但没有太多关于一致地复制这些组件的开发指南。

例如,我实际上是在尝试重新创建此单元格:

这些单元格是否有任何标准布局?如果不是,您认为处理这种单元格布局的最佳方法是什么?

目前我遇到的问题是做这种事情:

<LinearLayout>
    <ImageView/>
    <LinearLayout>
        <TextView/>
        <TextView/>
    </LinearLayout>
    <ImageView/>
</LinearLayout>

从不显示第二个图像视图。

建议?是根据我的具体情况还是标准布局?

更新

我的观点奏效了。正如有人建议的那样,它是LinearLayout weights。最后为了让它工作,我有两个ImageViews,权重为1,内部LinearLayout,权重为0。

对不起,如果这是一个关于初学者主题的长问题 - 将它留给问题的更一般的部分 - 标准组件的标准布局。 (可能是 Stack Overflow 新文档部分的候选者。)

【问题讨论】:

  • 从不显示第二个 ImageView - 为什么不呢?你的重量总和设置不正确吗?

标签: android listview components


【解决方案1】:

Google 并没有真正为这些 Material Design 规范制定标准布局。

这是一个基于规范的布局,可帮助您入门:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="88dp">

    <ImageView
        android:id="@+id/image_view"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="16dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="20dp"
        tools:src="@drawable/ic_error_white_24dp"/>

    <TextView
        android:id="@+id/text_view1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="72dp"
        android:layout_marginStart="72dp"
        android:layout_marginRight="56dp"
        android:layout_marginEnd="56dp"
        android:layout_marginTop="16dp"
        android:maxLines="1"
        android:textSize="16sp"
        android:textColor="?android:attr/textColorPrimary"
        tools:text="This is the title line"/>

    <TextView
        android:id="@+id/text_view2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_below="@+id/text_view1"
        android:layout_marginLeft="72dp"
        android:layout_marginStart="72dp"
        android:layout_marginRight="56dp"
        android:layout_marginEnd="56dp"
        android:maxLines="1"
        android:textSize="14sp"
        android:textColor="?android:attr/textColorSecondary"
        tools:text="This is the second line"/>

    <TextView
        android:id="@+id/text_view3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_below="@+id/text_view2"
        android:layout_marginLeft="72dp"
        android:layout_marginStart="72dp"
        android:layout_marginRight="56dp"
        android:layout_marginEnd="56dp"
        android:maxLines="1"
        android:textSize="14sp"
        android:textColor="?android:attr/textColorSecondary"
        tools:text="This is the third line"/>

    <ImageView
        android:id="@+id/image_view_2"
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentTop="true"
        android:layout_marginRight="16dp"
        android:layout_marginEnd="16dp"
        android:layout_marginTop="20dp"
        tools:src="@drawable/ic_error_white_24dp"/>

</RelativeLayout>

请注意,我没有使用尺寸值和文本样式;这是你可以经历和做的事情。这只是为了让您走上正轨。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多