欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android 沉浸式狀態(tài)欄及懸浮效果

 更新時(shí)間:2016年11月15日 11:32:30   作者:小_源  
這篇文章主要介紹了Android 沉浸式狀態(tài)欄及懸浮效果的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

一、概述

現(xiàn)在大多數(shù)的電商APP的詳情頁(yè)長(zhǎng)得幾乎都差不多,幾乎都是上面一個(gè)商品的圖片,當(dāng)你滑動(dòng)的時(shí)候,會(huì)有Tab懸浮在上面,這樣做用戶體驗(yàn)確實(shí)不錯(cuò),如果Tab滑上去,用戶可能還需要滑下來,在來點(diǎn)擊Tab,這樣確實(shí)很麻煩。沉浸式狀態(tài)欄那,郭霖說過谷歌并沒有給出沉浸式狀態(tài)欄這個(gè)明白,谷歌只說了沉浸式模式(Immersive Mode)。不過沉浸式狀態(tài)欄這個(gè)名字其實(shí)聽不粗,隨大眾吧,但是Android的環(huán)境并沒有iOS環(huán)境一樣特別統(tǒng)一,比如華為rom的跟小米rom的虛擬按鍵完全不一樣,所有Android開發(fā)者不容易。。。。。

二、淘寶的效果

這里寫圖片描述

三、我們的效果

這里寫圖片描述 

只能傳2M,把我的美女都給壓失真了。。。。。。

四、實(shí)現(xiàn)類

自定義ScrollView (StickyScrollView)

StatusBarUtil //非常不錯(cuò)的狀態(tà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">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.xiaoyuan.StickyScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true">
<LinearLayout
android:id="@+id/ll_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="500dip"
android:background="@mipmap/meinv"/>
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:text="美" />
<TextView
android:layout_width="match_parent"
android:layout_height="50dip"
android:gravity="center"
android:text="女"/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dip"
android:gravity="center"
android:text="美"/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dip"
android:gravity="center"
android:text="不"/>
<TextView
android:layout_width="match_parent"
android:layout_height="50dip"
android:gravity="center"
android:text="美"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:tag="sticky">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="#ffffff"
android:orientation="horizontal">
<TextView
android:id="@+id/infoText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="美女信息"
android:textColor="#000000"
android:textSize="16dp" />
<TextView
android:id="@+id/secondText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="美女介紹"
android:textColor="#000000"
android:textSize="16dp" />
</LinearLayout>
</LinearLayout>
<FrameLayout
android:id="@+id/tabMainContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:minHeight="400dp">
</FrameLayout>
</LinearLayout>
</com.xiaoyuan.StickyScrollView>
<RelativeLayout
android:id="@+id/ll_good_detail"
android:layout_width="match_parent"
android:layout_height="49dp"
android:background="#00000000"
android:paddingTop="@dimen/spacing_normal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dip"
android:layout_centerHorizontal="true"
android:text="返回"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dip"
android:text="美女"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:layout_alignParentRight="true"
android:layout_marginRight="10dip"
android:layout_centerHorizontal="true"
android:text="分享"/>
</RelativeLayout>
</FrameLayout>
</RelativeLayout>

注意:我們把要懸浮的Tab設(shè)置了android:tag=”sticky”這樣的屬性

六、實(shí)現(xiàn)代碼

public class MainActivity extends AppCompatActivity implements View.OnClickListener, StickyScrollView.OnScrollChangedListener {
TextView oneTextView, twoTextView;
private StickyScrollView stickyScrollView;
private int height;
private LinearLayout llContent;
private RelativeLayout llTitle;
private FrameLayout frameLayout;
private TextView title;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
initListeners();
}
/**
* 初始化View
*/
private void initView() {
stickyScrollView = (StickyScrollView) findViewById(R.id.scrollView);
frameLayout = (FrameLayout) findViewById(R.id.tabMainContainer);
title = (TextView) findViewById(R.id.title);
oneTextView = (TextView) findViewById(R.id.infoText);
llContent = (LinearLayout) findViewById(R.id.ll_content);
llTitle = (RelativeLayout) findViewById(R.id.ll_good_detail);
oneTextView.setOnClickListener(this);
twoTextView = (TextView) findViewById(R.id.secondText);
twoTextView.setOnClickListener(this);
stickyScrollView.setOnScrollListener(this);
StatusBarUtil.setTranslucentForImageView(MainActivity.this, 0, title);
FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) llTitle.getLayoutParams();
params.setMargins(0, getStatusHeight(), 0, 0);
llTitle.setLayoutParams(params);
//默認(rèn)設(shè)置一個(gè)Frg
getSupportFragmentManager().beginTransaction().replace(R.id.tabMainContainer, Fragment.newInstance()).commit();
}
/**
* 獲取狀態(tài)欄高度
* @return
*/
private int getStatusHeight() {
int resourceId = MainActivity.this.getResources().getIdentifier("status_bar_height", "dimen", "android");
return getResources().getDimensionPixelSize(resourceId);
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.infoText) {
getSupportFragmentManager().beginTransaction().replace(R.id.tabMainContainer, Fragment.newInstance()).commit();
} else if (v.getId() == R.id.secondText) {
getSupportFragmentManager().beginTransaction().replace(R.id.tabMainContainer, Fragment1.newInstance()).commit();
}
}
private void initListeners() {
//獲取內(nèi)容總高度
final ViewTreeObserver vto = llContent.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
height = llContent.getHeight();
//注意要移除
llContent.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
}
});
//獲取Fragment高度
ViewTreeObserver viewTreeObserver = frameLayout.getViewTreeObserver();
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
height = height - frameLayout.getHeight();
//注意要移除
frameLayout.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
}
});
//獲取title高度
ViewTreeObserver viewTreeObserver1 = llTitle.getViewTreeObserver();
viewTreeObserver1.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
height = height - llTitle.getHeight() - getStatusHeight();//計(jì)算滑動(dòng)的總距離
stickyScrollView.setStickTop(llTitle.getHeight() + getStatusHeight());//設(shè)置距離多少懸浮
//注意要移除
llTitle.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
}
});
}
@Override
public void onScrollChanged(int l, int t, int oldl, int oldt) {
if (t <= 0) {
llTitle.setBackgroundColor(Color.argb((int) 0, 255, 255, 255));
StatusBarUtil.setTranslucentForImageView(MainActivity.this, 0, title);
} else if (t > 0 && t <= height) {
float scale = (float) t / height;
int alpha = (int) (255 * scale);
llTitle.setBackgroundColor(Color.argb((int) alpha, 227, 29, 26));//設(shè)置標(biāo)題欄的透明度及顏色
StatusBarUtil.setTranslucentForImageView(MainActivity.this, alpha, title);//設(shè)置狀態(tài)欄的透明度
} else {
llTitle.setBackgroundColor(Color.argb((int) 255, 227, 29, 26));
StatusBarUtil.setTranslucentForImageView(MainActivity.this, 255, title);
}
}
}

注意:stickyScrollView.setStickTop(int height)我們通過這個(gè)方法可以設(shè)置Tab距離多高開始懸浮

我們通過監(jiān)聽ScrollView滑動(dòng)距離來不斷改變我們標(biāo)題欄跟狀態(tài)欄的透明度來達(dá)到效果,在這里我們計(jì)算了幾個(gè)高度(滑動(dòng)距離)。最后來算出滑動(dòng)總距離,根據(jù)滑動(dòng)的距離跟滑動(dòng)的總距離來算出透明度的數(shù)值。

StatusBarUtil.setTranslucentForImageView(MainActivity.this, 0, title);我們通過工具來實(shí)現(xiàn)圖片深入狀態(tài)欄。里面的傳的View是圖片下面的View。

以上所述是小編給大家介紹的Android 沉浸式狀態(tài)欄及懸浮效果,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Flutter實(shí)現(xiàn)抽屜動(dòng)畫

    Flutter實(shí)現(xiàn)抽屜動(dòng)畫

    這篇文章主要為大家詳細(xì)介紹了Flutter實(shí)現(xiàn)抽屜動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-03-03
  • JetpackCompose Scaffold組件使用教程

    JetpackCompose Scaffold組件使用教程

    在今年的Google/IO大會(huì)上,亮相了一個(gè)全新的 Android 原生 UI 開發(fā)框架-Jetpack Compose, 與蘋果的SwiftIUI一樣,Jetpack Compose是一個(gè)聲明式的UI框架
    2023-01-01
  • Android實(shí)現(xiàn)短信驗(yàn)證碼獲取自動(dòng)填寫功能(詳細(xì)版)

    Android實(shí)現(xiàn)短信驗(yàn)證碼獲取自動(dòng)填寫功能(詳細(xì)版)

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)短信驗(yàn)證碼獲取自動(dòng)填寫功能,很實(shí)用的功能分享給大家,感興趣的小伙伴們可以參考一下
    2016-08-08
  • Android編程單選項(xiàng)框RadioGroup綜合應(yīng)用示例

    Android編程單選項(xiàng)框RadioGroup綜合應(yīng)用示例

    這篇文章主要介紹了Android編程單選項(xiàng)框RadioGroup用法,結(jié)合實(shí)例形式分析了Android單選按鈕組RadioGroup的定義與具體使用技巧,需要的朋友可以參考下
    2016-10-10
  • Android 異步加載圖片分析總結(jié)

    Android 異步加載圖片分析總結(jié)

    研究了android從網(wǎng)絡(luò)上異步加載圖像,現(xiàn)總結(jié)如下,感興趣的朋友可以了解下哈
    2013-06-06
  • 分享實(shí)現(xiàn)Android圖片選擇的兩種方式

    分享實(shí)現(xiàn)Android圖片選擇的兩種方式

    本文給大家分享的是Android選擇圖片的兩種方式的實(shí)現(xiàn)代碼,分別是單張選取和多張批量選取,非常的實(shí)用,有需要的小伙伴可以參考下
    2016-01-01
  • Kotlin?launch原理全面分析

    Kotlin?launch原理全面分析

    在Android開發(fā)中,launch是我們經(jīng)常用的,今天來看看它是什么原理,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧
    2022-11-11
  • Android6.0 消息機(jī)制原理解析

    Android6.0 消息機(jī)制原理解析

    這篇文章主要為大家詳細(xì)介紹了Android6.0 消息機(jī)制原理,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-09-09
  • Android自定義封裝banner組件

    Android自定義封裝banner組件

    這篇文章主要為大家詳細(xì)介紹了Android自定義封裝banner組件的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-06-06
  • Android實(shí)現(xiàn)懸浮窗效果

    Android實(shí)現(xiàn)懸浮窗效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)懸浮窗效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04

最新評(píng)論