最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android中Toolbar隨著ScrollView滑動(dòng)透明度漸變效果實(shí)現(xiàn)

 更新時(shí)間:2017年01月22日 10:53:36   作者:Luyifei666  
這篇文章主要介紹了Android中Toolbar隨著ScrollView滑動(dòng)透明度漸變效果實(shí)現(xiàn),非常不錯(cuò),具有參考借鑒價(jià)值,需要的的朋友參考下

Android中Toolbar隨著ScrollView滑動(dòng)透明度漸變效果實(shí)現(xiàn)

一.思路:監(jiān)聽ScrollView的滑動(dòng)事件 不斷的修改Toolbar的透明度

二.注意

1.ScrollView 6.0以前沒有scrollView.setOnScrollChangeListener(l)方法  所以要自定義ScrollView 在onScrollChanged()中監(jiān)聽

2.ScrollView 6.0(23)以前沒有scrollView.setOnScrollChangeListener()方法  所以要自定義ScrollView 實(shí)現(xiàn).為了Toolbar不遮蓋ScrollView我們給ScrollView設(shè)置paddingTop

   但是ScrollView 設(shè)置paddintTop以后 Toolbar透明度變?yōu)?以后還占據(jù)空間 會(huì)出現(xiàn)空白,解決方法:

 為ScrollView設(shè)置兩個(gè)屬性:

 1〉.

android:clipToPadding="false" 

表示控件的繪制范圍是否不在padding里面  false就是表示空間的繪制可以繪制到padding中

 2〉

android:clipChildren="false" 

表示子控件是否不能超出padding區(qū)域(比如: false :ScrollView上滑的時(shí)候 child 可以滑出padding區(qū)域 ;true:ScrollView上滑的時(shí)候 child 不能可以滑出padding區(qū)域 )

布局文件如下:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 xmlns:app="http://schemas.android.com/apk/res-auto" 
 xmlns:tools="http://schemas.android.com/tools" 
 android:layout_width="match_parent" 
 android:layout_height="match_parent" > 
 <com.dice.md.toolbar.transperent.TranslucentScrollView 
  android:id="@+id/scrollview" 
  android:clipToPadding="false" 
  android:clipChildren="true" 
  android:paddingTop="?attr/actionBarSize" 
  android:layout_width="match_parent" 
  android:layout_height="match_parent" > 
  <LinearLayout 
   android:orientation="vertical" 
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content"> 
   <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" 
    android:background="@android:color/holo_blue_dark" 
    /> 
   <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" 
    android:background="@android:color/holo_green_light" 
    /> 
   <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" 
    android:background="@android:color/holo_orange_light" 
    /> 
   <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" 
    android:background="@android:color/holo_blue_dark" 
    /> 
   <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" 
    android:background="@android:color/holo_green_light" 
    /> 
   <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" 
    android:background="@android:color/holo_orange_light" 
    /> 
   <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" 
    android:background="@android:color/holo_blue_dark" 
    /> 
   <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" 
    android:background="@android:color/holo_green_light" 
    /> 
   <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" 
    android:background="@android:color/holo_orange_light" 
    /> 
   <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" 
    android:background="@android:color/holo_blue_dark" 
    /> 
   <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" 
    android:background="@android:color/holo_green_light" 
    /> 
   <TextView 
    android:layout_width="fill_parent" 
    android:layout_height="400dp" 
    android:background="@android:color/holo_orange_light" 
    /> 
  </LinearLayout> 
 </com.dice.md.toolbar.transperent.TranslucentScrollView> 
 <android.support.v7.widget.Toolbar 
  android:id="@+id/toolbar" 
  android:layout_width="match_parent" 
  android:background="?attr/colorPrimary" 
  android:layout_height="?attr/actionBarSize" > 
 </android.support.v7.widget.Toolbar> 
</RelativeLayout> 

三.步驟

1. 創(chuàng)建回調(diào)接口:

public interface TranslucentListener { 
/** 
 * 透明度的回調(diào) 
 * @param alpha 
 */ 
public void onTranslucent(float alpha); 
} 

2.自定義ScrollView 在onScrollChange方法中回調(diào)TranslucentListener接口的方法 并且回傳alpha的值:

@Override 
protected void onScrollChanged(int l, int t, int oldl, int oldt) { 
 super.onScrollChanged(l, t, oldl, oldt); 
 if (translucentListener!=null) { 
  //translucentListener.onTranslucent(alpha); 
 } 
} 

3.alpha的值得計(jì)算:

// alpha = 滑出去的高度/(screenHeight/3); 
float heightPixels = getContext().getResources().getDisplayMetrics().heightPixels; 
float scrollY = getScrollY();//該值 大于0 
float alpha = 1-scrollY/(heightPixels/3);// 0~1 透明度是1~0 
//這里選擇的screenHeight的1/3 是alpha改變的速率 (根據(jù)你的需要你可以自己定義)

最后MainActivity中

@Override 
public void onTranslucent(float alpha) { 
 toolbar.setAlpha(alpha); 
} 

以上所述是小編給大家介紹的Android中Toolbar隨著ScrollView滑動(dòng)透明度漸變效果實(shí)現(xiàn),小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Android開發(fā)解決字符對齊問題方法

    Android開發(fā)解決字符對齊問題方法

    這篇文章主要為大家介紹了Android開發(fā)解決字符對齊問題方法詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-03-03
  • Android超詳細(xì)講解彈出多選框的實(shí)現(xiàn)

    Android超詳細(xì)講解彈出多選框的實(shí)現(xiàn)

    這篇文章主要介紹了在Android開發(fā)中如何實(shí)現(xiàn)彈出多選框的功能,多選框是很常見的操作控件,感興趣的朋友都來一起看看吧
    2022-03-03
  • 詳解Android中使用Notification實(shí)現(xiàn)進(jìn)度通知欄(示例三)

    詳解Android中使用Notification實(shí)現(xiàn)進(jìn)度通知欄(示例三)

    這篇文章主要介紹了詳解Android中使用Notification實(shí)現(xiàn)進(jìn)度通知欄(示例三),具有一定的參考價(jià)值,有興趣的可以了解一下。
    2016-12-12
  • Android?Notification使用教程詳解

    Android?Notification使用教程詳解

    這篇文章主要介紹了Android?Notification使用,通知的使用的內(nèi)容還是比較多的,此篇文章將會(huì)盡可能詳細(xì)的介紹Notification的內(nèi)容,需要的朋友可以參考下
    2022-07-07
  • android監(jiān)聽安裝和卸載示例

    android監(jiān)聽安裝和卸載示例

    Android應(yīng)用程序的安裝和卸載事件,是由系統(tǒng)進(jìn)行監(jiān)聽并全局廣播的,支持1.5(android 3)以上,因此,如果想要監(jiān)聽獲取應(yīng)用的安裝和卸載事件,只需要自定義一個(gè)BroadcastReceiver,來對系統(tǒng)廣播進(jìn)行監(jiān)聽和處理
    2014-02-02
  • Kotlin作用域函數(shù)之間的區(qū)別和使用場景詳解

    Kotlin作用域函數(shù)之間的區(qū)別和使用場景詳解

    這篇文章主要給大家介紹了關(guān)于Kotlin作用域函數(shù)之間的區(qū)別和使用場景的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2020-08-08
  • Android開發(fā)實(shí)現(xiàn)從相冊中選擇照片功能詳解

    Android開發(fā)實(shí)現(xiàn)從相冊中選擇照片功能詳解

    這篇文章主要介紹了Android開發(fā)實(shí)現(xiàn)從相冊中選擇照片功能,涉及Android權(quán)限控制、事件綁定、文件路徑與獲取等相關(guān)操作技巧,需要的朋友可以參考下
    2019-03-03
  • 詳解Android開發(fā)中ContentObserver類的使用

    詳解Android開發(fā)中ContentObserver類的使用

    這篇文章主要介紹了詳解Android開發(fā)中ContentObserver類的使用,ContentObserver內(nèi)容觀察者主要用來監(jiān)聽uri的改變請情況,需要的朋友可以參考下
    2016-04-04
  • Android 中 viewpager 滑動(dòng)指示器的實(shí)例代碼

    Android 中 viewpager 滑動(dòng)指示器的實(shí)例代碼

    本文通過實(shí)例代碼給大家介紹了android 中 viewpager 滑動(dòng)指示器,代碼簡單易懂,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-12-12
  • 仿iPhone風(fēng)格對話框(附件包含例子/jar包/jar包源碼)

    仿iPhone風(fēng)格對話框(附件包含例子/jar包/jar包源碼)

    這個(gè)對框完全繼承、仿照AlertDialog,只是實(shí)現(xiàn)了自定義效果;另外,沒有實(shí)現(xiàn)setIcon,因?yàn)閕phone中的對話框多數(shù)都沒有圖標(biāo);附件包含例子、jar包、jar包源碼
    2013-01-01

最新評論

交口县| 张北县| 镶黄旗| 尼勒克县| 泗水县| 体育| 平泉县| 方山县| 威宁| 富宁县| 岑溪市| 分宜县| 屯留县| 九台市| 雅江县| 孙吴县| 玉溪市| 商城县| 朝阳区| 阳新县| 怀柔区| 安远县| 梁河县| 大庆市| 中山市| 彭水| 含山县| 乌什县| 武汉市| 阿勒泰市| 桂阳县| 双江| 布拖县| 乐亭县| 汝城县| 出国| 常宁市| 沙坪坝区| 调兵山市| 于都县| 剑阁县|