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

Android之scrollview滑動(dòng)使標(biāo)題欄漸變背景色的實(shí)例代碼

 更新時(shí)間:2018年05月14日 13:16:33   作者:歲月LICHENGAN  
這篇文章主要介紹了Android之scrollview滑動(dòng)使標(biāo)題欄漸變背景色的實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

之前也是在網(wǎng)上看到這種效果,不過(guò)是滾動(dòng)listview來(lái)改變標(biāo)題欄的顏色,感覺那個(gè)應(yīng)用的比較少,比如我要滾動(dòng)scrollview來(lái)實(shí)現(xiàn)呢,那么問題就來(lái)了,廢話少說(shuō),看一下要實(shí)現(xiàn)的效果先(這是在項(xiàng)目應(yīng)用的效果)。

直接上源代碼:

一、核心類(ObservableScrollView.java)

package com.jukopro.titlebarcolor; 
import android.content.Context; 
import android.util.AttributeSet; 
import android.widget.ScrollView; 
/** 
 * 帶滾動(dòng)監(jiān)聽的scrollview 
 * 
 */ 
public class ObservableScrollView extends ScrollView { 
 public interface ScrollViewListener { 
  void onScrollChanged(ObservableScrollView scrollView, int x, int y, 
    int oldx, int oldy); 
 } 
 private ScrollViewListener scrollViewListener = null; 
 public ObservableScrollView(Context context) { 
  super(context); 
 } 
 public ObservableScrollView(Context context, AttributeSet attrs, 
   int defStyle) { 
  super(context, attrs, defStyle); 
 } 
 public ObservableScrollView(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); 
  } 
 } 
} 

二、具體使用(MainActivity.java)

package com.jukopro.titlebarcolor; 
import android.app.Activity; 
import android.graphics.Color; 
import android.os.Bundle; 
import android.view.ViewTreeObserver; 
import android.view.ViewTreeObserver.OnGlobalLayoutListener; 
import android.widget.ArrayAdapter; 
import android.widget.ImageView; 
import android.widget.ListView; 
import android.widget.TextView; 
import com.jukopro.titlebarcolor.ObservableScrollView.ScrollViewListener; 
public class MainActivity extends Activity implements ScrollViewListener{ 
 private ObservableScrollView scrollView; 
 private ListView listView; 
 private ImageView imageView; 
 private TextView textView; 
 private int imageHeight; 
 @Override 
 protected void onCreate(Bundle savedInstanceState) { 
  super.onCreate(savedInstanceState); 
  setContentView(R.layout.activity_main); 
  scrollView = (ObservableScrollView) findViewById(R.id.scrollview); 
  listView = (ListView) findViewById(R.id.listview); 
  imageView = (ImageView) findViewById(R.id.imageview); 
  textView = (TextView) findViewById(R.id.textview); 
  initListeners(); 
  initData(); 
 } 
 private void initListeners() { 
  // 獲取頂部圖片高度后,設(shè)置滾動(dòng)監(jiān)聽 
  ViewTreeObserver vto = imageView.getViewTreeObserver(); 
  vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { 
   @Override 
   public void onGlobalLayout() { 
    imageView.getViewTreeObserver().removeGlobalOnLayoutListener( 
      this); 
    imageHeight = imageView.getHeight(); 
    scrollView.setScrollViewListener(MainActivity.this); 
   } 
  }); 
 } 
 private void initData() { 
  ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.data)); 
  listView.setAdapter(adapter); 
 } 
 @Override 
 public void onScrollChanged(ObservableScrollView scrollView, int x, int y, 
   int oldx, int oldy) { 
  // TODO Auto-generated method stub 
  // Log.i("TAG", "y--->" + y + " height-->" + height); 
  if (y <= 0) { 
   textView.setBackgroundColor(Color.argb((int) 0, 227, 29, 26));//AGB由相關(guān)工具獲得,或者美工提供 
  } else if (y > 0 && y <= imageHeight) { 
   float scale = (float) y / imageHeight; 
   float alpha = (255 * scale); 
   // 只是layout背景透明(仿知乎滑動(dòng)效果) 
   textView.setBackgroundColor(Color.argb((int) alpha, 227, 29, 26)); 
  } else { 
   textView.setBackgroundColor(Color.argb((int) 255, 227, 29, 26)); 
  } 
 } 
} 

三、XML(activity_main.xml)

<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="${relativePackage}.${activityClass}" > 
 <com.jukopro.titlebarcolor.ObservableScrollView 
  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/imageview" 
    android:layout_width="match_parent" 
    android:layout_height="200dp" 
    android:background="@drawable/zuqiu" /> 
   <com.jukopro.titlebarcolor.MyListview 
    android:id="@+id/listview" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
   </com.jukopro.titlebarcolor.MyListview> 
  </LinearLayout> 
 </com.jukopro.titlebarcolor.ObservableScrollView> 
 <TextView 
  android:id="@+id/textview" 
  android:layout_width="match_parent" 
  android:layout_height="48dp" 
  android:gravity="center" 
  android:text="我是標(biāo)題" 
  android:textSize="18sp" 
  android:textColor="@android:color/white" 
  android:background="#00000000" /> 
</RelativeLayout>
 

還不懂的童鞋可以下載源代碼.

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。

相關(guān)文章

  • Android仿微信網(wǎng)絡(luò)加載彈出框

    Android仿微信網(wǎng)絡(luò)加載彈出框

    這篇文章主要為大家詳細(xì)介紹了Android仿微信網(wǎng)絡(luò)加載彈出框,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-06-06
  • Android IPC進(jìn)程間通信詳解最新AndroidStudio的AIDL操作)

    Android IPC進(jìn)程間通信詳解最新AndroidStudio的AIDL操作)

    這篇文章主要介紹了Android IPC進(jìn)程間通信的相關(guān)資料,需要的朋友可以參考下
    2016-09-09
  • Android頂欄定時(shí)推送消息

    Android頂欄定時(shí)推送消息

    在用安卓設(shè)備時(shí),經(jīng)常會(huì)應(yīng)用到彈出推送消息。接下來(lái)通過(guò)本文給大家介紹Android頂欄定時(shí)推送消息,感興趣的朋友一起學(xué)習(xí)吧
    2016-04-04
  • Android入門之在SharedPreference中使用加密

    Android入門之在SharedPreference中使用加密

    這篇文章主要為大家詳細(xì)介紹了Android如何使在SharedPreference中使用加密,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)Android有一定的幫助,需要的可以參考一下
    2022-12-12
  • Android 自定義圖片地圖坐標(biāo)功能的實(shí)現(xiàn)

    Android 自定義圖片地圖坐標(biāo)功能的實(shí)現(xiàn)

    最近項(xiàng)目要求實(shí)現(xiàn)一個(gè)在自定義地圖圖片上添加坐標(biāo)信息的功能,類似于在圖片做標(biāo)注的功能,這種功能糾結(jié)該如何實(shí)現(xiàn)呢?下面小編通過(guò)實(shí)例代碼給大家介紹Android 自定義地圖的實(shí)現(xiàn),需要的朋友參考下吧
    2021-07-07
  • Android不顯示開機(jī)向?qū)Ш烷_機(jī)氣泡問題

    Android不顯示開機(jī)向?qū)Ш烷_機(jī)氣泡問題

    這篇文章主要介紹了Android不顯示開機(jī)向?qū)Ш烷_機(jī)氣泡問題,需要的朋友可以參考下
    2019-05-05
  • Android Koin2基本使用的那件事兒

    Android Koin2基本使用的那件事兒

    這篇文章主要給大家介紹了關(guān)于Android Koin2基本使用的那件事兒,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)各位Android開發(fā)者們具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • android開發(fā)修改狀態(tài)欄背景色和圖標(biāo)顏色的示例

    android開發(fā)修改狀態(tài)欄背景色和圖標(biāo)顏色的示例

    本篇文章主要介紹了android開發(fā)修改狀態(tài)欄背景色和圖標(biāo)顏色的示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-01-01
  • Android之復(fù)選框?qū)υ捒蛴梅▽?shí)例分析

    Android之復(fù)選框?qū)υ捒蛴梅▽?shí)例分析

    這篇文章主要介紹了Android之復(fù)選框?qū)υ捒蛴梅?涉及Android頁(yè)面布局、對(duì)話框類等相關(guān)使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-09-09
  • Java程序員轉(zhuǎn)Android開發(fā)必讀經(jīng)驗(yàn)一份

    Java程序員轉(zhuǎn)Android開發(fā)必讀經(jīng)驗(yàn)一份

    小編最近幾日偷偷的發(fā)現(xiàn)部分Java程序員想轉(zhuǎn)安卓開發(fā),故此加緊補(bǔ)充知識(shí),為大家搜集資料,積極整理前人的經(jīng)驗(yàn),希望可以給正處于困惑中的你,帶來(lái)些許的幫助。
    2017-11-11

最新評(píng)論

永兴县| 长春市| 博罗县| 于田县| 浠水县| 庐江县| 海伦市| 邢台市| 阿坝| 阳新县| 景东| 贺州市| 兴仁县| 乌拉特后旗| 商水县| 邵武市| 濉溪县| 衡水市| 呈贡县| 延川县| 泰和县| 蕲春县| 渭南市| 霸州市| 定日县| 疏附县| 安达市| 芮城县| 荥经县| 贺州市| 绥芬河市| 阳高县| 临江市| 肇东市| 德令哈市| 阳信县| 河源市| 宜兴市| 平凉市| 张北县| 中卫市|