android 仿QQ五毛特效之查看红包领取详情界面

2024-08-21 02:32

本文主要是介绍android 仿QQ五毛特效之查看红包领取详情界面,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

这篇是15年写的 没有审核成功,今天看到,重新发布了下,没想到发布成功了~~!

 

首先我们看下 上下滑动的效果

   

从左到右依次为 往上滑动的截图 

发现在滑动的过程中可以发现以下3点:

1、 发起者 的部分 进行了缩放  ,我们一般缩放的对象的为图片 

2、然后在qq的这个界面发起者的部分不可点击 没有点击事件

3、手指上下滑动多少 ,界面就回滑动多少  

我们继续分析这样的布局滑动无非就是ScrollView 之类的自定义类

根据我们发现的几点可以分析出以下3点:

1、发起者部分可能在ScrollView布局中因为它看起来像是可以滑动

2、发起者部分应该是画的图片

3、根据发现的第3点可以否定上面第一点,原因是:如果在滑动的过程中发起者的部分进行缩放了,那么滑动的距离应该比手机滑动的要多

根据以上分析我们可以猜想出这个钱包领取详情几面的布局

最大的布局为RelativeLayout
第一个child为发起者的图片部分 不用填写属性
第二个child为全屏的ScrollView 同样不用写属性 
这样我们看到ScrollView 覆盖在发起者图片部分上方
然后ScrollView的布局组成部分为
第一个child为一个与发起者图片部分同等大小的透明的View
第二个就是下方的列表ListView等 
发起者部分的宽度为屏幕的宽度,我们可以根据一定的比例  宽:高=3  设置发起者部分,ScrollView中透明部分宽高  
		//屏幕的宽高单位为px,所以我们在布局中需要转换为dpwidth = ScreenUtils.getScreenWidth(this);height = ScreenUtils.getScreenHeight(this);
    /** * 获得屏幕宽度 *  */  public static int getScreenWidth(Context context) {  WindowManager wm = (WindowManager) context  .getSystemService(Context.WINDOW_SERVICE);  DisplayMetrics outMetrics = new DisplayMetrics();  wm.getDefaultDisplay().getMetrics(outMetrics);  int width = outMetrics.widthPixels;  return width;  }  /** * 获得屏幕高度 */  public static int getScreenHeight(Context context) {  WindowManager wm = (WindowManager) context  .getSystemService(Context.WINDOW_SERVICE);  DisplayMetrics outMetrics = new DisplayMetrics();  wm.getDefaultDisplay().getMetrics(outMetrics);  int height = outMetrics.heightPixels;  return height;  }  

需要写一个自定义的ScrollView 来获取滚动的高度

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;//重写ScrollViewpublic class NotifyingScrollView extends ScrollView {/*** @author Cyril Mottier*/public interface OnScrollChangedListener {void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt);}private OnScrollChangedListener mOnScrollChangedListener;public NotifyingScrollView(Context context) {super(context);}public NotifyingScrollView(Context context, AttributeSet attrs) {super(context, attrs);}public NotifyingScrollView(Context context, AttributeSet attrs, int defStyle) {super(context, attrs, defStyle);}/*** t 为目前滑动的高度 */@Overrideprotected void onScrollChanged(int l, int t, int oldl, int oldt) {super.onScrollChanged(l, t, oldl, oldt);if (mOnScrollChangedListener != null) {mOnScrollChangedListener.onScrollChanged(this, l, t, oldl, oldt);}}public void setOnScrollChangedListener(OnScrollChangedListener listener) {mOnScrollChangedListener = listener;}}

MainActivity代码
package com.yqy.cmd;import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;import com.yqy.cmd.NotifyingScrollView.OnScrollChangedListener;public class MainActivity extends Activity {private ImageView topIv;private NotifyingScrollView mySv;private View view;private LinearLayout myLl;private int width;private int height;private int allowHeight;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);topIv = (ImageView) findViewById(R.id.topIv);mySv = (NotifyingScrollView) findViewById(R.id.mySv);view = findViewById(R.id.view);myLl = (LinearLayout) findViewById(R.id.myLl);//屏幕的宽高单位为px,所以我们在布局中需要转换为dpwidth = ScreenUtils.getScreenWidth(this);height = ScreenUtils.getScreenHeight(this);allowHeight = Utils.px2dip(this, height) / 3;topIv.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, Utils.px2dip(this, height) / 3));view.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, Utils.px2dip(this, height) / 3));mySv.setOnScrollChangedListener(new OnScrollChangedListener() {@Overridepublic void onScrollChanged(ScrollView who, int l, int t, int oldl, int oldt) {if(t < allowHeight){int height = allowHeight - t;topIv.setLayoutParams(new RelativeLayout.LayoutParams(height*3, height));}}});}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {getMenuInflater().inflate(R.menu.main, menu);return true;}}

activity_main布局
<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"android:background="@android:color/holo_red_light"tools:context=".MainActivity"tools:ignore="NewApi" ><ImageViewandroid:id="@+id/topIv"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@drawable/ic_launcher" /><com.yqy.cmd.NotifyingScrollViewandroid:id="@+id/mySv"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_alignParentLeft="true"android:layout_alignParentTop="true" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical" ><Viewandroid:id="@+id/view"android:layout_width="match_parent"android:layout_height="80dp" /><LinearLayoutandroid:id="@+id/myLl"android:layout_width="match_parent"android:layout_height="1000dp"android:background="@android:color/white"android:orientation="vertical" ></LinearLayout></LinearLayout></com.yqy.cmd.NotifyingScrollView></RelativeLayout>

看下运行效果(比较丑)
 

 

 

 

这篇关于android 仿QQ五毛特效之查看红包领取详情界面的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1091861

相关文章

Android实现两台手机屏幕共享和远程控制功能

《Android实现两台手机屏幕共享和远程控制功能》在远程协助、在线教学、技术支持等多种场景下,实时获得另一部移动设备的屏幕画面,并对其进行操作,具有极高的应用价值,本项目旨在实现两台Android手... 目录一、项目概述二、相关知识2.1 MediaProjection API2.2 Socket 网络

Android实现悬浮按钮功能

《Android实现悬浮按钮功能》在很多场景中,我们希望在应用或系统任意界面上都能看到一个小的“悬浮按钮”(FloatingButton),用来快速启动工具、展示未读信息或快捷操作,所以本文给大家介绍... 目录一、项目概述二、相关技术知识三、实现思路四、整合代码4.1 Java 代码(MainActivi

Android Mainline基础简介

《AndroidMainline基础简介》AndroidMainline是通过模块化更新Android核心组件的框架,可能提高安全性,本文给大家介绍AndroidMainline基础简介,感兴趣的朋... 目录关键要点什么是 android Mainline?Android Mainline 的工作原理关键

如何解决idea的Module:‘:app‘platform‘android-32‘not found.问题

《如何解决idea的Module:‘:app‘platform‘android-32‘notfound.问题》:本文主要介绍如何解决idea的Module:‘:app‘platform‘andr... 目录idea的Module:‘:app‘pwww.chinasem.cnlatform‘android-32

Android实现打开本地pdf文件的两种方式

《Android实现打开本地pdf文件的两种方式》在现代应用中,PDF格式因其跨平台、稳定性好、展示内容一致等特点,在Android平台上,如何高效地打开本地PDF文件,不仅关系到用户体验,也直接影响... 目录一、项目概述二、相关知识2.1 PDF文件基本概述2.2 android 文件访问与存储权限2.

Android Studio 配置国内镜像源的实现步骤

《AndroidStudio配置国内镜像源的实现步骤》本文主要介绍了AndroidStudio配置国内镜像源的实现步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、修改 hosts,解决 SDK 下载失败的问题二、修改 gradle 地址,解决 gradle

在Android平台上实现消息推送功能

《在Android平台上实现消息推送功能》随着移动互联网应用的飞速发展,消息推送已成为移动应用中不可或缺的功能,在Android平台上,实现消息推送涉及到服务端的消息发送、客户端的消息接收、通知渠道(... 目录一、项目概述二、相关知识介绍2.1 消息推送的基本原理2.2 Firebase Cloud Me

Android中Dialog的使用详解

《Android中Dialog的使用详解》Dialog(对话框)是Android中常用的UI组件,用于临时显示重要信息或获取用户输入,本文给大家介绍Android中Dialog的使用,感兴趣的朋友一起... 目录android中Dialog的使用详解1. 基本Dialog类型1.1 AlertDialog(

mysql如何查看当前连接数

《mysql如何查看当前连接数》:本文主要介绍mysql如何查看当前连接数问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mysql查看当前连接数查看mysql数据库允许最大连接数总结mysql查看当前连接数查看当前连接数SHOW STATUS LIKE

Android Kotlin 高阶函数详解及其在协程中的应用小结

《AndroidKotlin高阶函数详解及其在协程中的应用小结》高阶函数是Kotlin中的一个重要特性,它能够将函数作为一等公民(First-ClassCitizen),使得代码更加简洁、灵活和可... 目录1. 引言2. 什么是高阶函数?3. 高阶函数的基础用法3.1 传递函数作为参数3.2 Lambda