0

我有 ListActivity 由许多行组成,我试图自定义行之间的分隔线,所以我可以给分隔线:角半径,更改它的颜色并应用边框等等,

我试图将它引用到可绘制的形状布局,但它不起作用,强制关闭。

列表活动代码:

   public class Rows extends ListActivity {
      String classes[] = { "row1", "row2", "row3",  "row4", "row5"};                    
  @Override
      protected void onCreate(Bundle savedInstanceState) {
        this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
       // TODO Auto-generated method stub
         super.onCreate(savedInstanceState);

  ListView lv = getListView();   
  lv.setCacheColorHint(0);  
  lv.setSelector(android.R.color.transparent); 
  lv.setDivider(new ColorDrawable(this.getResources().getColor(R.drawable.divider)));  
  lv.setPadding(20, 0, 20, 0);
  lv.setVerticalScrollBarEnabled(false);
  lv.setBackgroundResource(R.drawable.list_background);

setListAdapter(new MyArrayAdapter(this, classes));  }

divider.xml 代码:

 <?xml version="1.0" encoding="utf-8" ?> 
   <shape xmlns:android="http://schemas.android.com/apk/res/android"
       android:shape="rectangle">
    <stroke android:width="5dp" android:height="5dp" android:color="#B22222" /> 
    <solid android:color="#FFFFFF" /> 
    <padding android:left="10dp"  android:right="10dp"  /> 
    <corners android:radius="10dp" android:bottomRightRadius="5dp"
       android:bottomLeftRadius="5dp" android:topLeftRadius="10dp"
         android:topRightRadius="10dp" /> 
   </shape>

任何帮助将不胜感激,谢谢

4

1 回答 1

0

你不应该ColorDrawable首先使用。如果您的列表参数是非条件的,为什么不直接在 XML 中设置它:

android:divider="@drawable/divider"
于 2013-04-07T11:14:57.567 回答