0

我是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>

任何帮助将不胜感激。

4

1 回答 1

1

我终于通过添加解决了这个问题

    android:cacheColorHint="#0000"
    android:listSelector="#0000"

到我的列表视图。

干杯!

于 2013-08-08T10:50:42.477 回答