簡體   English   中英

設置listView分隔線的寬度

[英]Set listView divider's width

我試圖將listView與分隔符一起使用,而我正要更改分隔符的寬度,所以我在網站上查找了以下解決方案:

Listview分隔符頁邊距

在我的應用中進行測試時,我沒有分隔線,但是如果我切換為使用簡單的顏色,分隔線會再次出現

這是我的代碼:

我的活動布局:

android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
    android:layout_width="match_parent"
    android:layout_height="80sp"
    android:elegantTextHeight="true"
    android:text="Paramètres"
    android:textSize="24sp"
    android:gravity="center"
    android:textColor="#ffffff"
    android:background="#191919"/>
<ListView
    android:id="@+id/list"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:dividerHeight="2dp"
    android:divider="@drawable/list_divider">
</ListView>

</LinearLayout>

list_divider.xml

<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:insetLeft="15dp"
android:insetRight="15dp" >

<shape
    android:shape="rectangle" >
    <stroke
        android:dashGap="1dp"
        android:dashWidth="1.5dip"
        android:width="2dp"
        android:color="#000000" />

    <size android:height="3dp"/>

</shape>

</inset>

您為分頻器屬性指定了錯誤的文件名。更改此行

android:divider="@drawable/list_devider"

android:divider="@drawable/list_divider"

因為您的列表分隔符可繪制文件名為list_divider而不是list_devider

我建議您將px用作dividerHeight而不是dp

如果您指定1dp或1dip,Android將按比例縮小。 在120dpi的設備上,轉換后的像素變為0.75px,四舍五入為0。在某些設備上,轉換為2-3像素,通常看起來很丑或草率。

對於分隔線,如果要使用1像素分隔線,則1px是正確的高度,並且是“一切都應浸入”規則的例外之一。 在所有屏幕上均為1像素。 此外,在hdpi及以上屏幕上,通常1px的效果更好

所以我修改了我的listdivide.xml文件,它起作用了:

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetLeft="16dp"
    android:insetRight="16dp">

    <shape>
        <solid android:color="#000000" />
        <corners android:radius="1dp" />
    </shape>

</inset>

但是我仍然不知道為什么第一個不起作用:)

暫無
暫無

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

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