簡體   English   中英

分頻器不適用於Android Studio中的ListView

[英]Divider not working for ListView in Android studio

我正在嘗試為ListView中的列表項添加間距。 我試過使用divider和dividerHeight,但這似乎不起作用。 請問可能有什么問題嗎?

<?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:id="@+id/activity_export_logistics"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.orume.export.ExportLogisticsActivity">


<include layout="@layout/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"></include>


<ListView
    android:id="@+id/ListView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:divider="@null"
    android:dividerHeight="16dp"
    android:layout_marginTop="65dp"
    android:background="#fff"></ListView>
</RelativeLayout>

Divider.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line" >

<stroke
    android:width="20dp"
    android:color="#dd0d0d" />

</shape>

您沒有將分隔符設置為ListView
android:divider="@null" @null在這里意味着您將分隔符設置為空。 現在您有了一個可繪制的divider.xml ,並且需要告訴Android您希望將其用作分隔符。

如果您的divider.xml放在drawable目錄下,請使用android:divider="@drawable/divider"

好。 找到了出路。 我最終將android:layout_marginBottom添加到定義了ListView的texView中,並且效果很好。 謝謝。

為列表項創建一個自定義視圖,並在該自定義項布局內進行頂部和底部填充或其他空間調整,以為列表項帶來空間。 eg鏈接位於Android自定義RowItem的ListView下面

另外要注意的是,分配器的高度可能無法正常工作。

<ListView
    android:id="@+id/ListView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:divider="@android:color/transparent"
    android:dividerHeight="16dp"
    android:layout_marginTop="65dp"
    android:background="#fff"></ListView>

將此列表視圖替換為您的列表視圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM