我是Android的新手,所以请原谅我的无知。所以基本上我正在做一个自定义列表视图,其中我选择它在其角落四舍五入。我现在正在做的是关于listSelector。我正在查看this帖子并应用了作者发布的内容,但我在按下顶部和底部列表时遇到了问题。高光仍然是矩形而不是圆角。
更新
public class CustomAdapter extends CursorAdapter
{
LayoutInflater inflater;
@SuppressWarnings("deprecation")
public CustomAdapter(Context context, Cursor c) {
super(context, c);
inflater = LayoutInflater.from(context);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return inflater.inflate(R.layout.custom_row, parent, false);
}
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
int position = cursor.getPosition();
int mCount = cursor.getCount();
if (position == 0) && mCount == 1) {
view.setBackgroundResource(R.drawable.selector_rounded_corner_top);
} else if (position == 0) {
view.setBackgroundResource(R.drawable.selector_rounded_corner_top);
} else if (position == mCount - 1) {
view.setBackgroundResource(R.drawable.rounded_corner_bottom);
} else {
view.setBackgroundResource(R.drawable.list_entry_middle);
}
SELECTOR_ROUNDED_CORNER_TOP.XML
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/rounded_corner_pressed_top"
android:state_pressed="true" />
<item android:drawable="@drawable/rounded_corner_top"
android:state_focused="true" />
<item android:drawable="@drawable/rounded_corner_top" />
</selector>
rounded_corner_pressed_top.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<stroke android:width="1dp" android:color="#0000" />
<corners android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
/>
</shape>
</item>
<item android:top="1dp" android:left="1dp" android:right="1dp" android:bottom="1dp">
<shape >
<solid android:color="#FFB84D" />
<corners android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp" />
</shape>
</item>
</layer-list>
任何帮助都会有所帮助。
答案 0 :(得分:1)
我终于通过添加
解决了这个问题 android:cacheColorHint="#0000"
android:listSelector="#0000"
到我的列表视图。
干杯!