简体   繁体   English

ListView圆角选择器问题

[英]Listview rounded corner selector issue

I'm a newbie in Android so pardon my ignorance. 我是Android的新手,请原谅我的无知。 So basically I'm doing a custom listview wherein I have chosen it to be rounded on its corners. 所以基本上我正在做一个自定义列表视图,其中我选择了将其四舍五入。 What I'm doing right now is about the listSelector. 我现在正在做的是关于listSelector的。 I'm looking up from this post and applied what the author posted, but I'm having an issue in pressing the top and bottom list. 我从这篇文章中查找并应用了作者发布的内容,但是在按顶部和底部列表时出现问题。 The highlight is still rectangle not rounded. 高光仍然是矩形而不是圆形。

UPDATE: 更新:

   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_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 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>

Any help will do and be appreciated. 任何帮助都可以,我们将不胜感激。

I finally solved the problem by adding 我终于通过添加解决了这个问题

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

to my listview. 到我的列表视图。

Cheers! 干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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