分享

关于android:scrollbarStyle属性

 univasity 2017-02-07
1. activity_maim.xml
[html] view plaincopy
  1. <LinearLayout xmlns:android="http://schemas./apk/res/android"  
  2.     android:layout_width="fill_parent"  
  3.     android:layout_height="fill_parent"  
  4.     android:orientation="vertical" >  
  5.   
  6.     <ScrollView  
  7.         android:id="@+id/view1"  
  8.         android:layout_width="100dip"  
  9.         android:layout_height="120dip"  
  10.         android:background="@android:color/white"  
  11.         android:padding="8dip"  
  12.         android:scrollbarStyle="insideOverlay" >  
  13.   
  14.         <TextView  
  15.             android:layout_width="fill_parent"  
  16.             android:layout_height="wrap_content"  
  17.             android:background="@android:color/darker_gray"  
  18.             android:text="scroll_text scroll_text scroll_text scroll_text scroll_text scroll_text scroll_text"  
  19.             android:textColor="#ffffff" />  
  20.     </ScrollView>  
  21.   
  22.     <ScrollView  
  23.         android:id="@+id/view2"  
  24.         android:layout_width="100dip"  
  25.         android:layout_height="120dip"  
  26.         android:background="@android:color/white"  
  27.         android:padding="8dip"  
  28.         android:scrollbarStyle="insideInset" >  
  29.   
  30.         <TextView  
  31.             android:layout_width="fill_parent"  
  32.             android:layout_height="wrap_content"  
  33.             android:background="@android:color/darker_gray"  
  34.             android:text="scroll_text scroll_text scroll_text scroll_text scroll_text scroll_text scroll_text"  
  35.             android:textColor="#ffffff" />  
  36.     </ScrollView>  
  37.   
  38.     <ScrollView  
  39.         android:id="@+id/view3"  
  40.         android:layout_width="100dip"  
  41.         android:layout_height="120dip"  
  42.         android:background="@android:color/white"  
  43.         android:padding="8dip"  
  44.         android:scrollbarStyle="outsideOverlay" >  
  45.   
  46.         <TextView  
  47.             android:layout_width="fill_parent"  
  48.             android:layout_height="wrap_content"  
  49.             android:background="@android:color/darker_gray"  
  50.             android:text="scroll_text scroll_text scroll_text scroll_text scroll_text scroll_text scroll_text"  
  51.             android:textColor="#ffffff" />  
  52.     </ScrollView>  
  53.   
  54.     <ScrollView  
  55.         android:id="@+id/view4"  
  56.         android:layout_width="100dip"  
  57.         android:layout_height="120dip"  
  58.         android:background="@android:color/white"  
  59.         android:padding="8dip"  
  60.         android:scrollbarStyle="outsideInset" >  
  61.   
  62.         <TextView  
  63.             android:layout_width="fill_parent"  
  64.             android:layout_height="wrap_content"  
  65.             android:background="@android:color/darker_gray"  
  66.             android:text="scroll_text scroll_text scroll_text scroll_text scroll_text scroll_text scroll_text"  
  67.             android:textColor="#ffffff" />  
  68.     </ScrollView>  
  69.   
  70. </LinearLayout>  

2. 运行结果截图:insideOverlay、insideInset、outsideOverlay、outsideInset分别对应下图左边解释!


3.android:scrollbarStyle可以定义滚动条的样式和位置,用于Listview、scrollview等滚动view,可选值有insideOverlay、insideInset、outsideOverlay、outsideInset四种。
其中inside和outside分别表示是否在view的padding区域内,overlay和inset表示覆盖在view上或是插在view后面,所以四种值分别表示:
insideOverlay:默认值,表示在padding区域内并且覆盖在view上
insideInset表示在padding区域内并且插入在view后面
outsideOverlay:表示在padding区域外并且覆盖在view上
outsideInset:表示在padding区域外并且插入在view后面
4.自定义scrollbar
android:scrollbars="vertical"  
android:fadeScrollbars="true"                               //true scrollbar不滚动隐藏  
android:scrollbarThumbVertical="@drawable/scrollbar"        //自定义scrollbar       
android:scrollbarTrackHorizontal="@drawable/scrollbar_bg"   //自定义scrollbar背景
android:scrollbarStyle="outsideInset"                       //scrollbar风格

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约