繁体   English   中英

ListView圆角选择器问题

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM