我有ListView,圓角實現像波紋管。Android:ListView,圓角問題
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/list_bg"
android:divider="#dbdbdb"
android:dividerHeight="1sp"
android:cacheColorHint="#00000000"
android:descendantFocusability="afterDescendants"
android:scrollbars="vertical">
</ListView>
其中list_bg.xml是:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ffffff"/>
<corners android:bottomLeftRadius="10dp"
android:bottomRightRadius="10dp"
android:topLeftRadius="10dp"
android:topRightRadius="10dp"
/>
</shape>
這給我圓角。 問題是每個項目都是RelativeLayout,左邊是TextView,右邊是ImageButton。這兩個視圖都具有按下,保存和默認狀態的自定義圖形。像這樣的東西。
+------------------------------------+
| TextView | ImageButton |
+------------------------------------+
問題是自定義圖形覆蓋ListView背景,因此在第一個和最後一個項目上的圓角。滾動時一切都很好。
我已經編寫了自定義適配器,並在getView方法中爲物品設置了正確的bg。
@Override
public View getView(int position, View view, ViewGroup parent) {
...
if(position == 0) {
mItemView.setBackgroundResource(R.drawable.cell_item_first_selector);
mImgBtn.setBackgroundResource(R.drawable.cell_btn_first_selector);
}
else if (position == mData.size() -1) {
mItemView.setBackgroundResource(R.drawable.cell_item_last_selector);
mImgBtn.setBackgroundResource(R.drawable.cell_btn_last_selector);
}
else {
mItemView.setBackgroundResource(R.drawable.cell_item_def_selector);
mImgBtn.setBackgroundResource(R.drawable.cell_btn_def_selector);
}
...
}
它的作品,但我不知道這是很好的解決方案。有沒有其他方法可以自動在Android視圖中四捨五入,而不僅僅是通過設置背景?
它沒有幫助。仍然第一個和最後一個項目圖形隱藏圓角。是否有唯一的解決方案爲第一個和最後一個項目設置不同的圖形 – Adrian
嗯,它應該工作。你能發佈一些更多的佈局代碼嗎? –