【问题标题】:Android ListView thumb ScrollBarAndroid ListView 拇指滚动条
【发布时间】:2023-03-28 19:53:01
【问题描述】:

我想看到以下拇指滚动条:

http://www.androidpatterns.com/uap_pattern/scroll-thumb

我看到的是:

我的 XML 布局是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="xxaassss"
        ads:loadAdOnCreate="true" >
    </com.google.ads.AdView>

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:divider="#b5b5b5"
        android:dividerHeight="1dp"
        android:listSelector="@drawable/list_selector" />

</LinearLayout>

我的 Java 代码在 Activity 类的 onCreate 中(我是从 Activity 类而不是 ListActivity 扩展的):

        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
ListView list=(ListView)findViewById(R.id.list);
ArrayList<HashMap<String, String>> categoriesList = new ArrayList<HashMap<String, String>>();

        for(int i=0;i<119;i++) {
            HashMap<String, String> map = new HashMap<String, String>();
            map.put(KEY_ID, String.valueOf(i));
            //map.put(KEY_TITLE, "hello");
            map.put(KEY_TITLE, Prayer.tip.getNthLine(i, true).replace("~", ""));
            map.put(KEY_ARTIST, "");
            map.put(KEY_DURATION, "");
            map.put(KEY_THUMB_URL, String.valueOf(getResources().getIdentifier("img" + i, "drawable", getPackageName())));
            categoriesList.add(map);

        }
        LazyAdapter adapter=new LazyAdapter(this, categoriesList);
        list.setAdapter(adapter);

        list.setFastScrollEnabled(true);

我没有发布 LazyAdapter 的代码,因为我认为它与快速拇指滚动条的样式无关。如果需要,我也可以发布该代码。

【问题讨论】:

  • 您看到滚动条拇指是因为您在 Android 4.0 或更高版本上运行您的应用程序。链接中的拇指来自 Android 2.3。您可以从上面发布的链接@Brijesh 获取该图像并使用它。

标签: android listview


【解决方案1】:

像这样更改你的 xml 代码

<com.google.ads.AdView
    android:id="@+id/adView"`enter code here`
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="xxaassss"
    ads:loadAdOnCreate="true" >
</com.google.ads.AdView>

<ListView
    android:id="@+id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:divider="#FFF"
    android:fadeScrollbars="false"
    style="@style/CustomTheme"
    android:scrollX="0px"
    android:scrollY="0px"
    android:scrollbarAlwaysDrawVerticalTrack="true"
    android:scrollbarSize="20dp"
    android:scrollbarStyle="outsideOverlay"
    android:scrollbars="vertical" />

按照你的风格

<style name="CustomTheme" parent="android:Theme">
<item name="android:scrollbarTrackVertical">@drawable/scroll_track</item>
<item name="android:scrollbarThumbVertical">@drawable/scroll_thumb</item>

在清单中喜欢

&lt;application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/CustomTheme"&gt;

【讨论】:

  • 我添加了这段代码,但在styles.xml中报错。有什么地方可以获取 scroll_track 和 scroll_thumb 图像
【解决方案2】:

只需更改 android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb" 并根据需要创建可绘制对象。

喜欢

<ListView android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb" /> 

在可绘制对象中:

<shape xmlns:android="http://schemas.android.com/apk/res/android" > 
    <gradient android:angle="0" android:endColor="#6699FF" android:startColor="#3333FF" />
    <corners android:radius="1dp" /> 
    <size android:width="1dp" /> 
</shape>

我想这就是你想要的!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-17
    • 1970-01-01
    • 2013-08-24
    • 2018-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多