0

I tried to used android:scrollbarThumbVertical="@drawable/scrollbar" parameter to add image as scrollbar. The scroll bar was changed but the problem is, it won't show the original size, it was streted depending on listview size (items). If the List item count is 20 means it show right dimension, it goes around 50 means, the scroll bar is stretched in entire view. Is there a way to avoid stretching. Here i will add my code with scroll bar image as well as my out put too.

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;
    }
}

My output image is,

my Scroll bar image is enter image description here

4

1 に答える 1

2

この画像にはdraw9パッチを使用してください:)

于 2012-11-29T10:21:11.037 に答える