Android--ListView捲軸樣式

來源:互聯網
上載者:User

當ListView的記錄超過4頁時才會顯示滑塊  java代碼:[html] package com.example.test0123;    import java.lang.reflect.Field;  import android.app.Activity;  import android.graphics.drawable.Drawable;  import android.os.Bundle;  import android.view.View;  import android.view.ViewGroup;  import android.widget.AbsListView;  import android.widget.BaseAdapter;  import android.widget.ListView;  import android.widget.TextView;    public class TestList extends Activity {      ListView lv;  www.2cto.com      protected void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.list);          lv = (ListView) findViewById(R.id.listView1);          lv.setAdapter(new ListAdapter());            try {              Field f = AbsListView.class.getDeclaredField("mFastScroller");              f.setAccessible(true);              Object o = f.get(lv);              f = f.getType().getDeclaredField("mThumbDrawable");              f.setAccessible(true);              Drawable drawable = (Drawable) f.get(o);              drawable = getResources().getDrawable(R.drawable.ic_launcher);              f.set(o, drawable);          } catch (Exception e) {              throw new RuntimeException(e);          }        }        public class ListAdapter extends BaseAdapter {            public int getCount() {              return 200;          }            public Object getItem(int position) {              return null;          }            public long getItemId(int position) {              return 0;          }            public View getView(int position, View convertView, ViewGroup parent) {              TextView tv = new TextView(TestList.this);              tv.setTextSize(30);              tv.setText("aaaaa" + position);              return tv;          }      }  }    list.xml代碼:設定fastScrollEnabled為true [html] <?xml version="1.0" encoding="utf-8"?>  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="match_parent"      android:layout_height="match_parent"      android:orientation="vertical" >        <ListView          android:id="@+id/listView1"          android:layout_width="match_parent"          android:layout_height="wrap_content"          android:fastScrollEnabled="true"          >      </ListView>  </LinearLayout>    

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.