當前位置:首頁 » 安卓系統 » android自定義滾動條

android自定義滾動條

發布時間: 2023-01-30 19:15:58

⑴ android,設計畫廊滾動條,三張圖片,一張圖片佔1/3滾動條,如圖所示,最好使用HorizontalScrollView

<HorizontalScrollView
android:layout_width="200dp"
android:layout_height="fill_parent">
<ListView
android:layout_width="400dp"
android:layout_height="fill_parent"
android:footerDividersEnabled="false"
android:headerDividersEnabled="false"
android:scrollingCache="false"
/>
</HorizontalScrollView>

⑵ Android中自定義scrollview設置背景色

很多開發者在做Android UI時不知道如何設置ScrollView滾動條控制項的滑塊顏色,其實通過ScrollView的xml布局屬性android:scrollbarThumbVertical可以關聯一個drawable對象,比如說在ScrollView中我們有
android:scrollbars="vertical" //滾動條是垂直的
android:scrollbarThumbVertical="@drawable/red" //垂直滾動條顏色為red,red可以是一個png的圖片或用shape組成的xml圖形文件組成的drawable對象。

⑶ 怎麼在android中出現滾動界面

使用ScrollView即可。

例如:

android:layout_width="fill_parent"

android:layout_height="fill_parent"

android:scrollbars="vertical"

android:fadingEdge="vertical"

>

android:orientation="vertical" android:layout_width="fill_parent"

android:layout_height="wrap_content" android:padding="10dip"

android:scrollbars="vertical"

>

注意的是:ScrollView也是一個layout布局,可以讓它的內容數據顯示不下的時候出現滾動條。但是不能在ScrollView中放置多個組件,Scrollview只能包裹一個子元素。可以在Scrollview中放置一個LinearLayout或其他layout來放置更多組件(Layout可以嵌套的)。

⑷ android listview 中如何設置滾動條中滑塊的樣式

mThumbDrawable
這個文件沒有,根本為崩潰;
並不是方法不好用,是你沒有抄全;
在實際應用中,該代碼會出現異常,通過對幾個sdk源碼的對比,發現Google會對其中的屬性做一些微調:
如在5.x中,「mFastScroller」改為了「mFastScroll」,4.4中則把「mThumbDrawable」改為「thumbDrawable」並設為了final,在5.x中又恢復成了private.
所以在實際應用中還需加以判斷。下面是針對4.4修改後的代碼:
由於class FastScroller沒有public屬性,無法直接導包獲取到,所以從用到該類的AbsListView中獲取。

try {
Field f = AbsListView.class.getDeclaredField("mFastScroller"); //獲取AbsListView中的屬性mFastScroller
f.setAccessible(true);//設置屬性可修改
Object o = f.get(listview);//得到listview實例
// Field[] fields = f.getType().getDeclaredFields();
// for (Field field : fields) {
// Log.v("TAG", field.getName());
// } //查看所有屬性名
f = f.getType().getDeclaredField("mThumbImage");//獲取屬性mThumbImage(由於 4.4中的thumbDrawable不可修改,所以直接取其imageview)
f.setAccessible(true);
ImageView img = (ImageView) f.get(o); //得到ImageView實例
img.setImageDrawable(getResources().getDrawable(R.drawable.icon));
f.set(o, img); //把編輯好的ImageView放進去
} catch (Exception e) {
throw new RuntimeException(e);
}

⑸ android TextView滾動條設置android:ellipsize="marquee" android:scrollbars="horizontal" android:marqu

1.你滾動條包含的列表項要超過頁面顯示範圍
2.mxl代碼中多所有的列表項都要包含在scroll中。(也就是scroll要把列表項括起來)
隨便給你段代碼 scroll裡面的內容不用仔細看,就是一些列表組件什麼的。注意sroll的格式就好了

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#ff888888">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff888888">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#ff888888">
<TextView android:layout_width="wrap_content" android:id="@+id/Text" android:layout_height="wrap_content" android:text="@string/title" android:layout_gravity="center" android:textColor="#ffff00ff" android:textSize="30sp" android:layout_marginBottom="10px" android:layout_marginTop="30px"></TextView>

<Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:text="@string/backlight" android:id="@+id/backlight"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/screen" android:text="@string/screen"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/speaker" android:text="@string/speaker"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/headset" android:text="@string/headset"></Button>
<Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:text="@string/vibrator" android:id="@+id/vibrator"></Button>
<Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/battery" android:text="@string/battery"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:text="@string/dial" android:id="@+id/dial"></Button><Button android:gravity="left" android:layout_width="fill_parent" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/fingerpaint" android:text="@string/fingerpaint"></Button>
<Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:text="@string/touchpanel" android:id="@+id/touchpanel"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:text="@string/gsensor" android:id="@+id/gsensor"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/camera" android:text="@string/camera"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/wifi" android:text="@string/wifi"></Button>

<Button android:id="@+id/picture" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:layout_width="fill_parent" android:text="@+string/picture"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/bluetooth" android:text="@string/bluetooth"></Button><Button android:layout_width="fill_parent" android:gravity="left" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:id="@+id/keypress" android:text="@string/keypress"></Button><Button android:id="@+id/locateme" android:text="GPS" android:layout_width="fill_parent" android:textSize="25sp" android:layout_height="50px" android:layout_marginBottom="2px" android:gravity="left"></Button>
</LinearLayout>
</ScrollView>

</LinearLayout>

⑹ Android: ListView怎麼自定義滾動條的寬度、高度、背景

你好, <ListView
android:id="@+id/mylist"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fastScrollEnabled="true"
android:focusable="true"
android:scrollbarSize="50dp" >
</ListView>
這是listView的xml文件
list = (ListView)this.findViewById(R.id.mylist);
try {
Field f = AbsListView.class.getDeclaredField("mFastScroller");
if(!f.isAccessible()){
f.setAccessible(true);
}
Object o = f.get(list);
f = f.getType().getDeclaredField("mThumbDrawable");
f.setAccessible(true);
Drawable drawable=(Drawable) f.get(o);
drawable = getResources().getDrawable(R.drawable.btn_back);
f.set(o,drawable);

} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
這是listView滾動條設置的背景,希望可以幫助到你

熱點內容
雲伺服器2m寬是多少 發布:2024-04-19 11:56:36 瀏覽:727
android層布局 發布:2024-04-19 11:52:13 瀏覽:770
1500元組裝伺服器電腦 發布:2024-04-19 11:47:25 瀏覽:468
qq改密碼怎麼改手機 發布:2024-04-19 11:39:17 瀏覽:968
電腦上如何看wifi密碼 發布:2024-04-19 11:34:14 瀏覽:415
java性能測試腳本 發布:2024-04-19 11:25:24 瀏覽:980
存儲成本與性能 發布:2024-04-19 11:16:18 瀏覽:168
linux根文件系統製作 發布:2024-04-19 11:16:12 瀏覽:746
光遇夏日活動什麼時候安卓上線 發布:2024-04-19 11:08:15 瀏覽:854
Java開羅 發布:2024-04-19 10:50:55 瀏覽:959