我試圖使用android:scrollbarThumbVertical="@drawable/scrollbar"
參數來添加圖像作爲滾動條。滾動條已更改,但問題是,它不會顯示原始大小,它取決於列表視圖大小(項目)。如果列表項數量爲20意味着它顯示了正確的尺寸,它約爲50意味着,滾動條在整個視圖中拉伸。有沒有辦法避免拉伸。在這裏,我將使用滾動條圖像添加我的代碼以及我的輸出。如何避免Android中的滾動條拉伸列表視圖
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#234232"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/hello"
android:textSize="20sp" />
<ListView
android:id="@+id/listView1"
android:layout_width="250dp"
android:layout_height="fill_parent"
android:fadeScrollbars="false"
android:fadingEdge="none"
android:scrollbarSize="12dip"
android:scrollbarStyle="outsideInset"
android:scrollbarThumbVertical="@drawable/scrollbar" >
</ListView>
</LinearLayout>
CustomScrollBarAndroidActivity.java
public class CustomScrollBarAndroidActivity extends Activity {
private ListView list;
private static List<String> listItems = initListItems();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
list = (ListView) findViewById(R.id.listView1);
list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listItems));
}
private static List<String> initListItems() {
List<String> list = new ArrayList<String>();
boolean isNotFinish = true;
int i = 0;
while(isNotFinish){
list.add("list item #" + i);
if (i > 50){
isNotFinish = false;
}
i++;
}
return list;
}
}
,
我的滾動條圖像
爲什麼不在圖像中間使用帶有拉伸區域的九個補丁圖像? – Luksprog
@Luksprog:對不起,我不知道如何使用九個補丁圖像。你可以plz指導我 – Aerrow