2017-03-23 4 views
0

リストビューがタッチされたときにスクロールしたいのですが、リストビュー内のアイテムの数に関係なくスクロールしないと消えたいと思っています。タッチ上でのみスクロールを表示するリストビュー

これが私の現在のスニペットが私のstyles.xmlはこのようになります

<?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> 

次のようになります。

<!-- 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を使用して、私はいずれかのみ常にまたは表示しない表示するように設定することができます。どのようにして私が望むものを達成することができますか。これは、リストビューがタッチされたときだけ表示することです。あなたのテーマで

+0

のメカニズムにアクセスすることです - 代替は反対の操作を行うことであろう'fastScrollAlwaysVisible'属性です。デフォルトの振る舞いは、 'ListView'に触れていないときにファーストスクロールバーを自動的に隠すことです。 –

+0

リストに1つの項目がある場合でも動作が必要です。私が画面に触れるたびに、スクロールが表示され、タッチしていないときは隠れるか退色するはずです –

+0

ああ、私はあなたが何を意味するかを見ます。ええ、なぜ?つまり、なぜ、ListViewがスクロール可能であるかを視覚的に示す必要があるのでしょうか? –

答えて

0

は、次のオーバーライドを行います

<style name="Theme.App" parent="android:Theme.Light"> 
    <item name="android:fadeScrollbars">true</item> 
</style> 

は、ここに最初の回答を参照してください:

Autohide scrollbars when not scrolling in a ListView

注:多くのアイテムを持っている場合、フェージングスクロールバーが唯一のフル(より表示されます画面)。 >スクロールバーが常に表示されている(How to always show scrollbar

最後の可能な解決策は、カスタムリストビューを作成します(リストビューから延びる)と何とかただ、削除、スクロールバー

+0

動作しません。スクロールが表示される項目がリストに多数ある場合のみですか?リストに1つのアイテムがある場合でもこの動作が必要です。 –

+0

私の最後の編集を参照してください(回答の最後の文) – ramden

+0

試してもうまくいかないようです。私はまだ1つのリスト項目を持っています。しかし、コードの詳細を追加しました。助けに感謝します –

関連する問題