【发布时间】:2014-04-25 11:55:28
【问题描述】:
帮助!我尝试了所有关于 SO 的答案,但无济于事
形状 xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<!-- stroke width must be 1px, see https://stackoverflow.com/questions/3979218/android-listview-divider -->
<stroke
android:width="1px"
android:color="#aaAAaa" />
</shape>
在 ListFragment 中:
public void onViewCreated(View v, Bundle bundle){
listView = getListView();
listView.setDivider(getActivity().getResources().getDrawable(R.drawable.xxxx));
listView.setDividerHeight(1);
setListAdapter(...);
}
适配器:
@Override public boolean areAllItemsEnabled(){return true;}
另外,分隔线不应该跨越整个列表视图的宽度,我想在左右两边都有一些填充。所以我认为一个可绘制的形状是必须的。
已编辑答案: 不要使用线条,而是使用矩形。 并按照这个填充: How to add padding to gradient <shape> in Android?
【问题讨论】:
-
尝试将宽度设置为 1 dp 以进行描边。这也可能有帮助。
-
您是否从 isEnabled 返回 true?检查this。可能会有所帮助。
标签: android android-listview android-listfragment