gpt4 book ai didi

Android - 如何布局类似于 iOS 表格 View 单元格的 ListView 项,其中包含图像、标题和副标题?

转载 作者:行者123 更新时间:2023-11-29 20:47:58 25 4
gpt4 key购买 nike

我正在尝试布置一个类似于常见 iOS 设计的 Android ListView 单元格 - 左边是一个图像,图像旁边有两个标签: enter image description here

我如何实现像带有图像、标题和副标题的基本 iOS 单元格一样的 Android 单元格布局?

但是,我不确定用于完成此任务的正确布局是什么。这是我正在尝试的方法,但它没有正确对齐元素:

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">

<TextView
android:id="@+id/api"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.47">

<ImageView
android:layout_width="@dimen/side_button_size"
android:layout_height="@dimen/side_button_size"
android:id="@+id/image"
android:layout_gravity="left|top"
android:background="@drawable/close_red" />

<TextView
android:id="@+id/title"
android:layout_width="246dp"
android:layout_height="82dp"
android:layout_gravity="center_horizontal|top"
android:text="This is title label" />

<TextView
android:id="@+id/subtitle"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_gravity="left|center_vertical"
android:text="This is subtitle label" />
</FrameLayout>

</LinearLayout>

最佳答案

使用一个包含 ImageView 的水平 LinearLayout 和另一个(这次是垂直的)LinearLayout 包含 2 个 TextViews.

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

<ImageView
android:layout_width="96dp"
android:layout_height="96dp" />

<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<Space
android:layout_width="match_parent"
android:layout_height="4dp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>

</LinearLayout>

简单地说:

+-----------+-----------+
| | TextView1 |
| ImageView | |
| | TextView2 |
+-----------+-----------+

关于Android - 如何布局类似于 iOS 表格 View 单元格的 ListView 项,其中包含图像、标题和副标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29924748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com