[英]Show scroll only on touch Listview
我想要在觸摸列表視圖時顯示滾動,並且想要在不觸摸時消失,而不管列表視圖中的項目數如何。
這是我當前的代碼段的樣子
<?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/list_profile"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="#40ffffff"
android:dividerHeight="1dp"
android:fastScrollEnabled="true"
android:scrollbarStyle="insideOverlay"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#B1FFFFFF" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingBottom="18dp"
android:paddingLeft="35dp"
android:paddingRight="35dp"
android:paddingTop="18dp">
<com.bleexample2.CustomView.MyEditText
android:id="@+id/edit_search"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="@drawable/bg_edit_text"
android:hint="성함을 입력해주세요"
android:lines="1" />
<ImageButton
android:id="@+id/btn_search"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="centerInside"
android:src="@drawable/ic_search" />
<ImageButton
android:id="@+id/btn_add_profile"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="centerInside"
android:src="@drawable/ic_add" />
</LinearLayout>
</LinearLayout>
我的styles.xml看起來像這樣:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:textColor">#c6c6c6</item>
<item name="android:editTextColor">@color/editTextTextColor</item>
<item name="android:fastScrollTrackDrawable">@drawable/fast_scrollbar_track</item>
<item name="android:fastScrollThumbDrawable">@drawable/ic_thumb</item>
</style>
<style name="AppTheme.CustomFastScrollBar" parent="AppTheme" >
<item name="android:fastScrollThumbDrawable">@drawable/scroll_bar_vertical_thumb</item>
<item name="android:fastScrollTrackDrawable">@drawable/scrollbar_vetical</item>
<item name="android:fadeScrollbars">false</item>
</style>
使用fastScrollAlwaysVisible我只能將其設置為始終顯示或不顯示。 我如何才能實現想要的功能,即僅在觸摸listview時顯示。
在您的主題中,進行以下覆蓋:
<style name="Theme.App" parent="android:Theme.Light">
<item name="android:fadeScrollbars">true</item>
</style>
看到這里第一個答案:
注意:僅當您有很多項目(超過全屏顯示)時,才會出現“褪色”滾動條。 替代方法是執行相反的操作->使滾動條始終可見( 如何始終顯示滾動條 )
最后一種可能的解決方案是創建一個自定義listview(從ListView擴展)並以某種方式訪問滾動條的機制
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.