【问题标题】:ListView image selector stays in place when scrolledListView 图像选择器在滚动时保持原位
【发布时间】:2014-05-29 04:08:22
【问题描述】:

我的ListView 图像选择器无法在原位不动,即使滚动时所选项目不再可见。

1st photo: Selected "One"
2nd photo: Scrolled up, a little of the brown selector is visible
3rd photo: Scrolled up again, brown selector is at "Eleven" position
4th photo: Scrolled up again, the same happens

为什么会这样?我想用listView.setSelector,因为它已经是ListView的方法了。

这是我的布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".EighthActivity" >

    <ListView
        android:id="@+id/listview_instructor"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:dividerHeight="1.5dp" >
    </ListView>

</RelativeLayout>

这是我的代码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_eighth);

    ListView listView = (ListView) findViewById(R.id.listview_instructor);
    listView.setSelector(R.drawable.bg_brown);

    // Defined Array values to show in ListView
    String[] values = new String[] { "One", "Two", "Three", "Four", "Five",
            "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve",
            "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen",
            "Eighteen", "Nineteen", "Twenty" };

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, android.R.id.text1, values);

    listView.setAdapter(adapter);
}

有没有人也遇到过这种情况?

【问题讨论】:

标签: android android-layout listview android-listview selector


【解决方案1】:

试试下面的代码:-

<ListView android:id="@+id/list" 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content" 
      android:layout_gravity="center"
      android:divider="@null" 
      android:dividerHeight="0dip"
      android:listSelector="@drawable/list_selector" />

【讨论】:

  • 在布局中声明ListView选择器没有任何作用,结果还是一样。这对使用ListView 选择器的其他人来说是否常见?
猜你喜欢
  • 1970-01-01
  • 2011-03-02
  • 1970-01-01
  • 2018-05-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-04
相关资源
最近更新 更多