2

这是我工作正常的代码,我只想在listview. 所以,我的问题是如何在listview. 注意:我只想添加边框,我可以在哪里放置边框?任何帮助将不胜感激。谢谢

<ListView android:id="@+id/listCategory"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:fadeScrollbars="true"
          android:fastScrollEnabled="true"
          android:listSelector="@drawable/listview_selector"
          android:dividerHeight="1dp"
          android:layout_below="@+id/gridlayout"
          android:visibility="gone"/>

listview_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_focused="true" android:drawable="@drawable/listview_selector_focussed" />
<item android:state_pressed="true" android:drawable="@drawable/listview_selector_pressed" />
</selector>

listview_selector_focussed.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#0a89f1" android:endColor="#56768d" android:angle="90" />
</shape>

listview_selector_pressed.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<gradient android:startColor="#0a89f1" android:endColor="#56768d" android:angle="90" />
</shape>
4

1 回答 1

0

添加页眉和页脚,它们将作为边框

  1. 在您的活动中,您将声明您的ListView;

    View v=new View(this);
    v.setLayoutParams(new LayoutParams(<width>,>height>));
    v.setBackgroundColor(<your color>);
    ListView list=(ListView)findViewById(R.id.listCategory);
    list.addHeader(v);
    list.addFooter(v);
    
  2. 在您的父布局元素的布局文件中

    <YourParentLayoutElement
    ...
    android:paddingTop="<your_value>"
    android:paddingBottom="<your_value>"
    >
    
于 2013-07-24T06:51:41.793 回答