iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android 沉浸式状态栏及悬浮效果
  • 750
分享到

Android 沉浸式状态栏及悬浮效果

沉浸式状态栏状态栏Android 2022-06-06 06:06:12 750人浏览 泡泡鱼
摘要

一、概述 现在大多数的电商APP的详情页长得几乎都差不多,几乎都是上面一个商品的图片,当你滑动的时候,会有Tab悬浮在上面,这样做用户体验确实不错,如果Tab滑上去,用户可能还

一、概述

现在大多数的电商APP的详情页长得几乎都差不多,几乎都是上面一个商品的图片,当你滑动的时候,会有Tab悬浮在上面,这样做用户体验确实不错,如果Tab滑上去,用户可能还需要滑下来,在来点击Tab,这样确实很麻烦。沉浸式状态栏那,郭霖说过谷歌并没有给出沉浸式状态栏这个明白,谷歌只说了沉浸式模式(Immersive Mode)。不过沉浸式状态栏这个名字其实听不粗,随大众吧,但是Android的环境并没有iOS环境一样特别统一,比如华为rom的跟小米rom的虚拟按键完全不一样,所有Android开发者不容易。。。。。

二、淘宝的效果

这里写图片描述

三、我们的效果

这里写图片描述 

只能传2M,把我的美女都给压失真了。。。。。。

四、实现类

自定义ScrollView (StickyScrollView)

StatusBarUtil //非常不错的状态栏工具

五、布局


<?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设置了android:tag=”sticky”这样的属性

六、实现代码


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();
}

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);
//默认设置一个Frg
getSupportFragmentManager().beginTransaction().replace(R.id.tabMainContainer, Fragment.newInstance()).commit();
}

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() {
//获取内容总高度
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();//计算滑动的总距离
stickyScrollView.setStickTop(llTitle.getHeight() + getStatusHeight());//设置距离多少悬浮
//注意要移除
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));//设置标题栏的透明度及颜色
StatusBarUtil.setTranslucentForImageView(MainActivity.this, alpha, title);//设置状态栏的透明度
} else {
llTitle.setBackgroundColor(Color.argb((int) 255, 227, 29, 26));
StatusBarUtil.setTranslucentForImageView(MainActivity.this, 255, title);
}
}
}

注意:stickyScrollView.setStickTop(int height)我们通过这个方法可以设置Tab距离多高开始悬浮

我们通过监听ScrollView滑动距离来不断改变我们标题栏跟状态栏的透明度来达到效果,在这里我们计算了几个高度(滑动距离)。最后来算出滑动总距离,根据滑动的距离跟滑动的总距离来算出透明度的数值。

StatusBarUtil.setTranslucentForImageView(MainActivity.this, 0, title);我们通过工具来实现图片深入状态栏。里面的传的View是图片下面的View。

以上所述是小编给大家介绍的Android 沉浸式状态栏及悬浮效果,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程网网站的支持!

您可能感兴趣的文章:Android 实现沉浸式状态栏的方法Android沉浸式状态栏微技巧(带你真正理解沉浸式模式)Android之沉浸式状态栏的实现方法、状态栏透明解决Android 沉浸式状态栏和华为虚拟按键冲突问题Android App仿QQ制作Material Design风格沉浸式状态栏Android 高仿QQ 沉浸式状态栏另外两种Android沉浸式状态栏实现思路Android沉浸式状态栏实现详解Android中的沉浸式状态栏效果实例快速解决Android7.0下沉浸式状态栏变灰的问题Android沉浸式状态栏 + actionBar渐变 + scrollView顶部伸缩效果Android编程中沉浸式状态栏的三种实现方式详解


--结束END--

本文标题: Android 沉浸式状态栏及悬浮效果

本文链接: https://www.lsjlt.com/news/23269.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • Android实现ImmersionBar沉浸式状态栏
    (一)效果图 (二)实现步骤: 1、在build.gradle中加上 implementation 'com.gyf.barlibrary:barlibrary:2.3.0' 2、设置页面为全屏 将上图中的 改为 3、 加入以下代...
    99+
    2023-08-31
    android android studio gradle
  • android沉浸式状态栏怎么实现
    要实现Android沉浸式状态栏,可以按照以下步骤进行操作:1. 在styles.xml文件中定义一个没有ActionBar的主题,...
    99+
    2023-09-27
    android
  • Android 实现沉浸式状态栏(包含顶部栏吸顶Layout CoordinatorLayout实现沉浸式状态栏)
    前言 Android状态栏默认是固定的黑底白字,这肯定是不被伟大的设计师所喜爱的,更有甚者,某些时候设计希望内容能够延伸到状态栏上部(例如顶部是大图的情况)。所幸的是随着Android版本的迭代,开发者对状态栏等控件有了更多的控制。Andr...
    99+
    2023-09-12
    android
  • Android中怎么实现沉浸式状态栏
    这篇文章给大家介绍Android中怎么实现沉浸式状态栏,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。在布局文件中第一个控件(一般是imageview或者textview)中添加两个属性。<!--沉浸式-->...
    99+
    2023-05-30
    android
  • 【UI篇】Android 沉浸式状态栏的那些事
    目录 window.decorView.systemUiVisibility 的参数常量1.View.SYSTEM_UI_FLAG_HIDE_NAVIGATION:(>=api16)2.View.SYSTEM_UI_FLAG_FUL...
    99+
    2023-08-17
    android ui kotlin
  • 如何在Android应用中实现一个沉浸式状态栏效果
    这篇文章将为大家详细讲解有关如何在Android应用中实现一个沉浸式状态栏效果,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。实现方法如下: @TargetApi(Build.VERSION...
    99+
    2023-05-31
    android roi
  • Android 详解沉浸式状态栏的实现流程
    目录去掉标题栏效果引入依赖沉浸状态栏颜色沉浸状态栏图片Android—沉浸式状态栏 我们的征程是星辰大海,而非人间烟尘 去掉标题栏 首先去掉对应主题下面的Android自带的Act...
    99+
    2024-04-02
  • Android沉浸式状态栏设计的实例代码
    本文介绍了android沉浸式状态栏,分享给大家,希望对大家有帮助一、概述现在主流的App设计风格很多都用到了Materail Design,今天我们就来简单的实现一下改变状态栏颜色、让状态栏透明这两种效果。二、实现状态栏设置颜色我们写一个...
    99+
    2023-05-30
    android 沉浸式状态栏 roi
  • Android应用怎么实现一个沉浸式状态栏
    这期内容当中小编将会给大家带来有关Android应用怎么实现一个沉浸式状态栏,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。效果。导航栏问题在Android中,顶部导航栏目前常用的两种实现方式,一个是通过T...
    99+
    2023-05-31
    android roi
  • Android沉浸式状态栏的实现流程是怎样的
    本篇内容主要讲解“Android沉浸式状态栏的实现流程是怎样的”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Android沉浸式状态栏的实现流程是怎样的”吧!Android—沉浸式状态栏我们的征...
    99+
    2023-06-25
  • Android 开发中怎么改变沉浸式状态栏的颜色
    这篇文章给大家介绍Android 开发中怎么改变沉浸式状态栏的颜色,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。这个是基于SystemBarTintManager更改的增加一个方法:用于更改MIUIV6系统上的状态栏字...
    99+
    2023-05-31
    android roi
  • 史上最完美的Android沉浸式状态导航栏攻略
    前言 最近我在小破站开发一款新App,叫高能链。我是一个完美主义者,所以不管对架构还是UI,我都是比较抠细节的,在状态栏和导航栏沉浸式这一块,我还是踩了挺多坑,费了挺多精力的。这次我将我踩坑,适配各机型总结出来的史上最完美的Android沉...
    99+
    2023-08-17
    android ui
  • 如何解决Android 沉浸式状态栏和华为虚拟按键冲突问题
    这篇文章主要介绍如何解决Android 沉浸式状态栏和华为虚拟按键冲突问题,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!先看下实现的效果图:这是我自己的手机,OnePlus 3T 7.1.1版本(免费广告,没给我钱的...
    99+
    2023-05-30
    android
  • vue项目中如何使用Hbuilder打包app 设置沉浸式状态栏
    这篇文章给大家分享的是有关vue项目中如何使用Hbuilder打包app 设置沉浸式状态栏的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。使用 Hbuilder新建好移动app项目...
    99+
    2024-04-02
  • Android应用怎么实现一个浮动状态栏效果
    这期内容当中小编将会给大家带来有关Android应用怎么实现一个浮动状态栏效果,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。首先:要实现的是浮动状态栏效果,通过在Activity的onCreate方法中调...
    99+
    2023-05-31
    android roi
  • 一个Activity中多个Fragment实现沉浸式状态栏的解决方法
    项目中遇到一个问题:一个Activity有多个Fragment,每个Fragment的沉浸式状态栏不一样,有的是红色,有的是黑色,有的是一张图片(图片的一部分在状态栏中显示),并且要要兼顾虚拟按键(常说的导航栏)遮盖住布局导致自己布局中的某...
    99+
    2023-05-31
    fragment 沉浸式 状态栏
  • Android如何实现状态栏白底黑字效果
    这篇文章给大家分享的是有关Android如何实现状态栏白底黑字效果的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。一、描述在项目中有的时候Ui设计状态栏背景颜色是白色的,虽然还挺好看,不过可坑了我们做程序的,需要对...
    99+
    2023-05-30
    android
  • Android实现状态栏(statusbar)渐变效果的示例
    前言qq最近更新搞了渐变式状态栏.然后...新需求就是要加这个.唉先来张效果图:常见的方式:设置Theme,状态栏透明. <item name="android:windowTranslucentStatus">true<...
    99+
    2023-05-30
    android 状态栏 渐变
  • 纯CSS实现响应式导航栏的悬浮效果的实现步骤
    纯CSS实现响应式导航栏的悬浮效果的实现步骤前言:随着移动互联网的快速发展,响应式设计成为了网页设计的一项重要的特性。在响应式设计中,导航栏是一个关键的组成部分。本文将介绍如何通过纯CSS实现响应式导航栏的悬浮效果,让导航栏在不同设备上自动...
    99+
    2023-10-24
    不需要使用JavaScript。
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作