2013-03-02 91 views
8

我可以知道如何更改LinearLayout中分隔線的顏色嗎?更改LinearLayout中分隔線的顏色

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="48dp" 
    android:orientation="horizontal" 
    android:divider="?android:attr/dividerVertical" 
    android:dividerPadding="12dip" 
    android:showDividers="middle" 
    android:background="#ff2d2d2d" > 
... 
</LinearLayout> 

我是否需要手動將Android SDK中的9個修補程序映像複製到我的項目中,並定義自己的屬性來引用它?

+0

是的,您可以創建自己的圖像(dividerVertical)並將其放在drawable中,並可以使用android:divider =「@ drawable/dividerVertical」來使用它。我已經嘗試過我的結局和工作 – 2013-03-02 05:15:33

回答

22

它看起來像android:divider屬性不接受顏色值。所以,你必須爲了得到它來創建一個單獨的分頻器繪製的作品:

divider.xml

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

    <size android:width="1dip" /> 
    <solid android:color="#f00" /> 

</shape> 

layout.xml

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="48dp" 
    android:orientation="horizontal" 
    android:divider="@drawable/divider" 
    android:dividerPadding="12dip" 
    android:showDividers="middle" 
    android:background="#ff2d2d2d" > 

而且,請注意,android:divider只適用於Android 3.0或更高版本,它不適用於以前的Android版本。

+0

你應該擺脫無效的答案。 – lhunath 2013-04-15 19:21:19

+0

@lhunath,編輯 – 2013-04-16 03:11:51

+0

如何在使用此xml時看不到分隔線?我甚至試圖使用不同的寬度,並在所有情況下顯示分頻器... – 2013-06-13 07:01:57

-2

這是我做的

 <ImageView 
      android:id="@+id/imgVwmarkupborder" 
      android:layout_width="280dp" 
      android:layout_height="2dp" 
      android:src="@android:color/white" /> 
-3
<View 
    android:layout_width="fill_parent" 
    android:layout_height="1dp" 
    android:background="@android:color/white"/> 

在我的方法,我用這一個..

+0

我知道這樣的方法。我只是想使用android:divider功能 – 2013-03-02 04:56:11

相關問題