MainActivity.java
public class MainActivity extends Activity {
ListView lv;
ArrayList<String> list = new ArrayList<String>();
ArrayAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv = (ListView) findViewById(R.id.lv);
for (int i = 0; i < 112; i++) {
list.add("第 " + (i + 1) + " 行");
}
adapter = new ArrayAdapter(this, android.R.layout.activity_list_item, android.R.id.text1, list);
lv.setAdapter(adapter);
}
}
ListView布局:
<LinearLayout 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">
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fastScrollEnabled="true" />
</LinearLayout>
这ListView布局代码中的:android:fastScrollEnabled="true" 1.如果是true并且数据有112个,右侧会出现一个可以拉动的快速默认滑动条 2.如果是true并且数据111个,不会出现
|