2012-04-02 77 views
5

在我的應用程序中,我有一個實現ListFragment.OnSelectedListener的FragmentActivity。如何在listFragment中設置divider屬性?

ListFragment使用擴展customrow.xml佈局的自定義適配器。

我想更改列表中的分隔線顏色和高度。

我想我需要使用android:divider屬性,但不知道具體如何。

我試圖把它在FragmentActivity的佈局,並在customrow.xml佈局,但它不工作...

customrow.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal" 
android:gravity="center_vertical" 
android:background="@drawable/item_selector" 
android:divider="#f19000" > 

...textview and imageview... 

</LinearLayout> 

編輯:解

謝謝大家的幫助! 問題是,我沒有誇大自定義XML我ListFragment ...

因此,創建一個新的list_fragment.xml並添加這樣的事情在我ListFragment的伎倆:

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
View view = inflater.inflate(R.layout.list_fragment, null); 
return view; 
} 

list_fragment .XML:

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

<ListView 
    android:id="@android:id/list" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:divider="#f19000" 
     android:dividerHeight="1dip" > 
    </ListView> 

</LinearLayout> 

另外,Android的:ID = 「@機器人:ID /列表」 是強制性的,不斷變化的ID別的東西導致崩潰。

android:divider="@android:color/transparent" 

例如:

回答

2

您還可以更改列表分隔的高度與此代碼

android:dividerHeight="1dip" 
1

你應該通過設置分隔顏色的ListView項。