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

解析ScrollView--仿QQ空間標(biāo)題欄漸變

 更新時(shí)間:2017年05月02日 08:53:57   作者:ganchuanpu  
本篇文章主要介紹了仿QQ空間標(biāo)題欄漸變的實(shí)現(xiàn)方法的相關(guān)知識(shí),具有很好的參考價(jià)值。下面跟著小編一起來(lái)看下吧

先看一下效果圖:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context="com.hankkin.gradationtitlebar.QQSpeakActivity">

 <com.hankkin.gradationscroll.GradationScrollView
  android:id="@+id/scrollview"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:scrollbars="none">
  <LinearLayout
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="vertical" >
   <ImageView
    android:id="@+id/iv_banner"
    android:scaleType="fitXY"
    android:src="@drawable/banner3"
    android:layout_width="match_parent"
    android:layout_height="200dp" />
   <com.hankkin.gradationscroll.NoScrollListview
    android:id="@+id/listview"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
   </com.hankkin.gradationscroll.NoScrollListview>
  </LinearLayout>
 </com.hankkin.gradationscroll.GradationScrollView>
 <TextView
  android:paddingBottom="10dp"
  android:id="@+id/textview"
  android:layout_width="match_parent"
  android:layout_height="55dp"
  android:gravity="center|bottom"
  android:text="我是標(biāo)題"
  android:textSize="18sp"
  android:textColor="@color/transparent"
  android:background="#00000000" />
</RelativeLayout>
public class GradationScrollView extends ScrollView {

 public interface ScrollViewListener {
  void onScrollChanged(GradationScrollView scrollView, int x, int y,
        int oldx, int oldy);
 }

 private ScrollViewListener scrollViewListener = null;

 public GradationScrollView(Context context) {
  super(context);
 }

 public GradationScrollView(Context context, AttributeSet attrs,
        int defStyle) {
  super(context, attrs, defStyle);
 }

 public GradationScrollView(Context context, AttributeSet attrs) {
  super(context, attrs);
 }

 public void setScrollViewListener(ScrollViewListener scrollViewListener) {
  this.scrollViewListener = scrollViewListener;
 }
 @Override
 protected void onScrollChanged(int x, int y, int oldx, int oldy) {
  super.onScrollChanged(x, y, oldx, oldy);
  if (scrollViewListener != null) {
   scrollViewListener.onScrollChanged(this, x, y, oldx, oldy);
  }
 }
}

我們需要獲取圖片的高度,并且設(shè)置滾動(dòng)監(jiān)聽(tīng),隨著滾動(dòng)的距離來(lái)設(shè)置標(biāo)題欄的顏色透明度和字體顏色的透明度

/**
 * 獲取頂部圖片高度后,設(shè)置滾動(dòng)監(jiān)聽(tīng)
*/
private void initListeners() {
  ViewTreeObserver vto = ivBanner.getViewTreeObserver();
  vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
   @Override
   public void onGlobalLayout() {
    textView.getViewTreeObserver().removeGlobalOnLayoutListener(
      this);
    height = ivBanner.getHeight();

    scrollView.setScrollViewListener(QQSpeakActivity.this);
   }
  });
 }
  
/**
  * 滑動(dòng)監(jiān)聽(tīng)
  * @param scrollView
  * @param x
  * @param y
  * @param oldx
  * @param oldy
*/
@Override
public void onScrollChanged(GradationScrollView scrollView, int x, int y,
        int oldx, int oldy) {
  // TODO Auto-generated method stub
  if (y <= 0) { //設(shè)置標(biāo)題的背景顏色
   textView.setBackgroundColor(Color.argb((int) 0, 144,151,166));
  } else if (y > 0 && y <= height) { //滑動(dòng)距離小于banner圖的高度時(shí),設(shè)置背景和字體顏色顏色透明度漸變
   float scale = (float) y / height;
   float alpha = (255 * scale);
   textView.setTextColor(Color.argb((int) alpha, 255,255,255));
   textView.setBackgroundColor(Color.argb((int) alpha, 144,151,166));
  } else { //滑動(dòng)到banner下面設(shè)置普通顏色
   textView.setBackgroundColor(Color.argb((int) 255, 144,151,166));
  }
 }

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

最新評(píng)論

漠河县| 民乐县| 呈贡县| 屏边| 崇文区| 监利县| 洛川县| 宁城县| 湘潭县| 鲜城| 铜山县| 龙海市| 平邑县| 吉林省| 高淳县| 兴化市| 渑池县| 儋州市| 新竹县| 通渭县| 闽清县| 汾西县| 九江县| 汤原县| 临猗县| 乌鲁木齐市| 读书| 岑巩县| 九龙坡区| 宜都市| 枣强县| 宣汉县| 江口县| 柳河县| 庄浪县| 郓城县| 鸡西市| 南郑县| 富裕县| 都匀市| 喀喇|