gpt4 book ai didi

android - 在 ListView 项中使用垂直线

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:05:05 25 4
gpt4 key购买 nike

我试图在 Android ListView 项目中显示一条垂直线。我在单元格的 XML 中定义它,但是当我在 ListView 中预览它时,它没有出现。

我知道这是一个问题,因为我在这里看到了很多问题,但没有看到任何真正的答案。

XML 非常标准:

单元格:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/appWhite" >

<View android:layout_width="5dp"
android:layout_height="match_parent"
android:background="@color/appGreen"
android:layout_alignParentLeft="true" />

<RelativeLayout
android:id="@+id/cell_trip_info_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/vertical_bar" >

<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cell_trip_name"
android:paddingTop="20dp"
android:paddingBottom="20dp"
android:textColor="#2c3e50"
android:paddingLeft="10dp"
android:text="adfadf" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cell_trip_country"
android:layout_below="@+id/cell_trip_name"
android:textColor="#2c3e50"
android:paddingLeft="10dp"
android:text="adfadf" />
</RelativeLayout>

<RelativeLayout android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/whole_container"
android:layout_alignParentRight="true" >

<RelativeLayout android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/appGreen"
android:id="@+id/cell_trip_date_box"
android:layout_alignTop="@+id/update_buttons"
android:layout_alignBottom="@+id/update_buttons"
android:padding="20dp" >

<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cell_tripstart_date"
android:layout_centerHorizontal="true"
android:textColor="#fff" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cell_date_thru"
android:text="@string/thru"
android:layout_below="@+id/cell_tripstart_date"
android:layout_centerHorizontal="true"
android:textColor="#fff" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/cell_tripend_date"
android:layout_below="@+id/cell_date_thru"
android:textColor="#fff"
android:layout_centerHorizontal="true" />

</RelativeLayout>

<RelativeLayout android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/update_buttons"
android:visibility="gone"
android:layout_toRightOf="@+id/cell_trip_date_box"
android:background="#e9e9e9"
android:padding="20dp" >

<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/cell_button_edit_trip"
android:src="@drawable/slide_edit"
android:adjustViewBounds="true"
android:contentDescription="@string/content_description" />

<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/cell_button_delete_trip"
android:src="@drawable/slide_delete"
android:layout_toRightOf="@+id/cell_button_edit_trip"
android:adjustViewBounds="true"
android:contentDescription="@string/content_description" />

</RelativeLayout>
</RelativeLayout>
</RelativeLayout>

最佳答案

我在另一篇文章中找到了原因和明显的解决方案/解决方法 Here

基本上,无论出于何种原因,RelativeLayouts 都无法与 ListView 项中的“match_parent”高度设置配合使用。建议改用 LinearLayout 的帖子的答案之一。所以我刚刚创建了一个新文件,其父 View 是一个 LinearLayout。然后,我创建了一个 RelativeLayout 子项,并将其他所有内容都扔进去了。

这次效果很好,我可以轻松地创建我的垂直线。

关于android - 在 ListView 项中使用垂直线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20106183/

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