【发布时间】: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