[英]Listview rounded corner selector issue
我是Android的新手,請原諒我的無知。 所以基本上我正在做一個自定義列表視圖,其中我選擇了將其四舍五入。 我現在正在做的是關於listSelector的。 我從這篇文章中查找並應用了作者發布的內容,但是在按頂部和底部列表時出現問題。 高光仍然是矩形而不是圓形。
更新:
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>
任何幫助都可以,我們將不勝感激。
我終於通過添加解決了這個問題
android:cacheColorHint="#0000"
android:listSelector="#0000"
到我的列表視圖。
干杯!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.