├── .gitignore
├── .idea
├── compiler.xml
├── copyright
│ └── profiles_settings.xml
├── gradle.xml
├── misc.xml
├── modules.xml
└── runConfigurations.xml
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── yyh
│ │ └── status
│ │ └── key
│ │ ├── MainActivity.java
│ │ ├── base
│ │ └── BaseActivity.java
│ │ ├── inteml
│ │ └── ActionBarClickListener.java
│ │ ├── utils
│ │ ├── ScreenUtils.java
│ │ ├── SizeUtils.java
│ │ └── StatusBarUtils.java
│ │ └── widget
│ │ ├── TranslucentActionBar.java
│ │ └── TranslucentScrollView.java
│ └── res
│ ├── layout
│ ├── actionbar_trans.xml
│ ├── activity_actionbar.xml
│ └── activity_main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ ├── b72d93a1b308ad9305cd36050dbf453c.jpg
│ ├── bg_avatar.png
│ ├── bg_banner_my.jpg
│ ├── dft_avatar.png
│ ├── ic_address.png
│ ├── ic_agent_my.png
│ ├── ic_consume_history.png
│ ├── ic_invite_my.png
│ ├── ic_launcher.png
│ ├── ic_left_light.png
│ ├── ic_luck_my.png
│ ├── ic_right_gray.png
│ ├── ic_set_my.png
│ ├── ic_shopcar_my.png
│ ├── ic_sign.png
│ ├── ic_teacher_my.png
│ ├── ic_wallet.png
│ └── iv_my_docotor.png
│ ├── mipmap-xxxhdpi
│ └── ic_launcher.png
│ ├── values-v19
│ └── styles.xml
│ ├── values-v21
│ └── styles.xml
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── colors.xml
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── readme.md
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
17 |
18 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 25
5 | buildToolsVersion "25.0.1"
6 | defaultConfig {
7 | applicationId "test.com"
8 | minSdkVersion 16
9 | targetSdkVersion 25
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile 'com.android.support:appcompat-v7:25.0.1'
28 | testCompile 'junit:junit:4.12'
29 | }
30 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in E:\02-Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yyh/status/key/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.yyh.status.key;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.view.View;
6 |
7 |
8 | import com.yyh.status.key.base.BaseActivity;
9 | import com.yyh.status.key.R;
10 | import com.yyh.status.key.inteml.ActionBarClickListener;
11 | import com.yyh.status.key.widget.TranslucentActionBar;
12 | import com.yyh.status.key.widget.TranslucentScrollView;
13 |
14 | /**
15 | * 类功能描述:
16 | * Android沉浸式状态栏 + scrollView顶部伸缩 + actionBar渐变
17 | * 博客地址:http://blog.csdn.net/androidstarjack
18 | * 公众号:终端研发部
19 | * @author yuyahao
20 | * @version 1.0
修改时间: 修改备注:
21 | */
22 | public class MainActivity extends BaseActivity implements ActionBarClickListener, TranslucentScrollView.TranslucentChangedListener {
23 |
24 | private TranslucentScrollView translucentScrollView;
25 | private TranslucentActionBar actionBar;
26 | private View zoomView;
27 |
28 | @Override
29 | protected void onCreate(@Nullable Bundle savedInstanceState) {
30 | super.onCreate(savedInstanceState);
31 | setContentView(R.layout.activity_main);
32 |
33 | init();
34 | }
35 |
36 | private void init() {
37 | actionBar = (TranslucentActionBar) findViewById(R.id.actionbar);
38 | //初始actionBar
39 | actionBar.setData("我的", 0, null, 0, null, null);
40 | //开启渐变
41 | actionBar.setNeedTranslucent();
42 | //设置状态栏高度
43 | actionBar.setStatusBarHeight(getStatusBarHeight());
44 |
45 | translucentScrollView = (TranslucentScrollView) findViewById(R.id.pullzoom_scrollview);
46 | //设置透明度变化监听
47 | translucentScrollView.setTranslucentChangedListener(this);
48 | //关联需要渐变的视图
49 | translucentScrollView.setTransView(actionBar);
50 |
51 | zoomView = findViewById(R.id.lay_header);
52 | //关联伸缩的视图
53 | translucentScrollView.setPullZoomView(zoomView);
54 | }
55 |
56 | @Override
57 | public void onLeftClick() {
58 |
59 | }
60 |
61 | @Override
62 | public void onRightClick() {
63 |
64 | }
65 |
66 | @Override
67 | public void onTranslucentChanged(int transAlpha) {
68 | actionBar.tvTitle.setVisibility(transAlpha > 48 ? View.VISIBLE : View.GONE);
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yyh/status/key/base/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.yyh.status.key.base;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import com.yyh.status.key.R;
7 | import com.yyh.status.key.utils.StatusBarUtils;
8 |
9 | /**
10 | * 类功能描述:
11 | * 父类
12 | * 博客地址:http://blog.csdn.net/androidstarjack
13 | * 公众号:终端研发部
14 | * @author yuyahao
15 | * @version 1.0 修改时间: 修改备注:
16 | */
17 | public abstract class BaseActivity extends AppCompatActivity {
18 | public String TAG = "BaseActivity";
19 |
20 | @Override
21 | protected void onCreate(@Nullable Bundle savedInstanceState) {
22 | super.onCreate(savedInstanceState);
23 | TAG = getClass().getName();
24 | StatusBarUtils.setColor(this,R.color.aaa);
25 | }
26 |
27 | /**
28 | * 获取状态栏高度
29 | *
30 | * @return
31 | */
32 | public int getStatusBarHeight() {
33 | //获取status_bar_height资源的ID
34 | int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
35 | if (resourceId > 0) {
36 | //根据资源ID获取响应的尺寸值
37 | return getResources().getDimensionPixelSize(resourceId);
38 | }
39 | return 0;
40 | }
41 |
42 | }
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yyh/status/key/inteml/ActionBarClickListener.java:
--------------------------------------------------------------------------------
1 | package com.yyh.status.key.inteml;
2 |
3 | /**
4 | * [ActionBar点击监听器]
5 | * Created by yanjunhui
6 | * on 2016/8/17.
7 | * email:303767416@qq.com
8 | */
9 | public interface ActionBarClickListener {
10 |
11 | void onLeftClick();
12 |
13 | void onRightClick();
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yyh/status/key/utils/ScreenUtils.java:
--------------------------------------------------------------------------------
1 | package com.yyh.status.key.utils;
2 |
3 | import android.content.Context;
4 | import android.util.DisplayMetrics;
5 | import android.view.WindowManager;
6 |
7 | public class ScreenUtils {
8 |
9 | public static int getScreenWidth(Context context) {
10 | WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
11 | DisplayMetrics metrics = new DisplayMetrics();
12 | manager.getDefaultDisplay().getMetrics(metrics);
13 | return metrics.widthPixels;
14 | }
15 |
16 | public static int getScreenHeight(Context context) {
17 | WindowManager manager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
18 | DisplayMetrics metrics = new DisplayMetrics();
19 | manager.getDefaultDisplay().getMetrics(metrics);
20 | return metrics.heightPixels;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yyh/status/key/utils/SizeUtils.java:
--------------------------------------------------------------------------------
1 | package com.yyh.status.key.utils;
2 |
3 | import android.content.Context;
4 |
5 | /**
6 | * 类功能描述:
7 | * 屏幕处理工具类
8 | * 博客地址:http://blog.csdn.net/androidstarjack
9 | * 公众号:终端研发部
10 | * @author yuyahao
11 | * @version 1.0 修改时间: 修改备注:
12 | */
13 | public class SizeUtils {
14 |
15 | public static int dip2px(Context context, float dpValue) {
16 | final float scale = context.getResources().getDisplayMetrics().density;
17 | return (int) (dpValue * scale + 0.5f);
18 | }
19 |
20 | /**
21 | * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
22 | */
23 | public static int px2dip(Context context, float pxValue) {
24 | final float scale = context.getResources().getDisplayMetrics().density;
25 | return (int) (pxValue / scale + 0.5f);
26 | }
27 |
28 | /**
29 | * 将px值转换为sp值,保证文字大小不变
30 | *
31 | * @param pxValue
32 | * @return
33 | */
34 | public static int px2sp(Context context, float pxValue) {
35 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
36 | return (int) (pxValue / fontScale + 0.5f);
37 | }
38 |
39 | /**
40 | * 将sp值转换为px值,保证文字大小不变
41 | *
42 | * @param spValue
43 | * @return
44 | */
45 | public static int sp2px(Context context, float spValue) {
46 | final float fontScale = context.getResources().getDisplayMetrics().scaledDensity;
47 | return (int) (spValue * fontScale + 0.5f);
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yyh/status/key/utils/StatusBarUtils.java:
--------------------------------------------------------------------------------
1 | package com.yyh.status.key.utils;
2 |
3 | import android.app.Activity;
4 | import android.os.Build;
5 | import android.view.View;
6 | import android.view.ViewGroup;
7 | import android.view.Window;
8 | import android.view.WindowManager;
9 | import android.widget.LinearLayout;
10 |
11 |
12 | /**
13 | * 类功能描述:
14 | * Android沉浸式状态栏 工具类
15 | * 博客地址:http://blog.csdn.net/androidstarjack
16 | * 公众号:终端研发部
17 | * @author yuyahao
18 | * @version 1.0 修改时间: 修改备注:
19 | */
20 | public class StatusBarUtils {
21 |
22 | /**
23 | * 使状态栏透明
24 | *
25 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏
26 | *
27 | * @param activity 需要设置的activity
28 | */
29 | public static void setTranslucent(Activity activity) {
30 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
31 | // 设置状态栏透明
32 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
33 | // 设置根布局的参数
34 | ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
35 | rootView.setFitsSystemWindows(true);
36 | rootView.setClipToPadding(true);
37 | }
38 | }
39 |
40 | /**
41 | * 设置状态栏颜色
42 | *
43 | * @param activity 需要设置的activity
44 | * @param color 状态栏颜色值
45 | */
46 | public static void setColor(Activity activity, int color) {
47 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
48 | // 设置状态栏透明
49 | // activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
50 | // // 生成一个状态栏大小的矩形
51 | // View statusView = createStatusView(activity, color);
52 | // // 添加 statusView 到布局中
53 | // ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
54 | // decorView.addView(statusView);
55 | // 设置根布局的参数
56 | // ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
57 | // rootView.setFitsSystemWindows(true);
58 | // rootView.setClipToPadding(true);
59 | //设置透明状态栏
60 | ViewGroup contentFrameLayout = (ViewGroup)activity.findViewById(Window.ID_ANDROID_CONTENT);
61 | View parentView = contentFrameLayout.getChildAt(0);
62 | if (parentView != null && Build.VERSION.SDK_INT >= 14) {
63 | parentView.setFitsSystemWindows(true);
64 | parentView.setBackgroundColor(color);
65 | }
66 | }
67 |
68 | }
69 |
70 | /**
71 | * 生成一个和状态栏大小相同的矩形条
72 | *
73 | * @param activity 需要设置的activity
74 | * @param color 状态栏颜色值
75 | * @return 状态栏矩形条
76 | */
77 | private static View createStatusView(Activity activity, int color) {
78 | // 获得状态栏高度
79 | int resourceId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
80 | int statusBarHeight = activity.getResources().getDimensionPixelSize(resourceId);
81 |
82 | // 绘制一个和状态栏一样高的矩形
83 | View statusView = new View(activity);
84 | LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
85 | statusBarHeight);
86 | statusView.setLayoutParams(params);
87 | statusView.setBackgroundColor(color);
88 | return statusView;
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yyh/status/key/widget/TranslucentActionBar.java:
--------------------------------------------------------------------------------
1 | package com.yyh.status.key.widget;
2 |
3 | import android.content.Context;
4 | import android.text.TextUtils;
5 | import android.util.AttributeSet;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 | import android.widget.LinearLayout;
9 | import android.widget.TextView;
10 |
11 | import com.yyh.status.key.R;
12 | import com.yyh.status.key.inteml.ActionBarClickListener;
13 |
14 |
15 | /**
16 | * 类功能描述:
17 | * Android沉浸式状态栏 + scrollView顶部伸缩 + actionBar渐变
18 | * 博客地址:http://blog.csdn.net/androidstarjack
19 | * 公众号:终端研发部
20 | * @author yuyahao
21 | * @version 1.0
修改时间: 修改备注:
22 | */
23 | public final class TranslucentActionBar extends LinearLayout {
24 |
25 | private View layRoot;
26 | private View vStatusBar;
27 | private View layLeft;
28 | private View layRight;
29 | public TextView tvTitle;
30 | private TextView tvLeft;
31 | private TextView tvRight;
32 | private View iconLeft;
33 | private View iconRight;
34 |
35 | public TranslucentActionBar(Context context) {
36 | this(context, null);
37 | }
38 |
39 | public TranslucentActionBar(Context context, AttributeSet attrs) {
40 | super(context, attrs);
41 | init();
42 | }
43 |
44 | public TranslucentActionBar(Context context, AttributeSet attrs, int defStyleAttr) {
45 | super(context, attrs, defStyleAttr);
46 | }
47 |
48 | private void init() {
49 | setOrientation(HORIZONTAL);
50 | View contentView = inflate(getContext(), R.layout.actionbar_trans, this);
51 | layRoot = contentView.findViewById(R.id.lay_transroot);
52 | vStatusBar = contentView.findViewById(R.id.v_statusbar);
53 | tvTitle = (TextView) contentView.findViewById(R.id.tv_actionbar_title);
54 | tvLeft = (TextView) contentView.findViewById(R.id.tv_actionbar_left);
55 | tvRight = (TextView) contentView.findViewById(R.id.tv_actionbar_right);
56 | iconLeft = contentView.findViewById(R.id.iv_actionbar_left);
57 | iconRight = contentView.findViewById(R.id.v_actionbar_right);
58 | }
59 |
60 | /**
61 | * 设置状态栏高度
62 | *
63 | * @param statusBarHeight
64 | */
65 | public void setStatusBarHeight(int statusBarHeight) {
66 | ViewGroup.LayoutParams params = vStatusBar.getLayoutParams();
67 | params.height = statusBarHeight;
68 | vStatusBar.setLayoutParams(params);
69 | }
70 |
71 | /**
72 | * 设置是否需要渐变
73 | */
74 | public void setNeedTranslucent() {
75 | setNeedTranslucent(true, false);
76 | }
77 |
78 | /**
79 | * 设置是否需要渐变,并且隐藏标题
80 | *
81 | * @param translucent
82 | */
83 | public void setNeedTranslucent(boolean translucent, boolean titleInitVisibile) {
84 | if (translucent) {
85 | layRoot.setBackgroundDrawable(null);
86 | }
87 | if (!titleInitVisibile) {
88 | tvTitle.setVisibility(View.GONE);
89 | }
90 | }
91 |
92 | /**
93 | * 设置标题
94 | *
95 | * @param strTitle
96 | */
97 | public void setTitle(String strTitle) {
98 | if (!TextUtils.isEmpty(strTitle)) {
99 | tvTitle.setText(strTitle);
100 | } else {
101 | tvTitle.setVisibility(View.GONE);
102 | }
103 | }
104 |
105 | /**
106 | * 设置数据
107 | *
108 | * @param strTitle
109 | * @param resIdLeft
110 | * @param strLeft
111 | * @param resIdRight
112 | * @param strRight
113 | * @param listener
114 | */
115 | public void setData(String strTitle, int resIdLeft, String strLeft, int resIdRight, String strRight, final ActionBarClickListener listener) {
116 | if (!TextUtils.isEmpty(strTitle)) {
117 | tvTitle.setText(strTitle);
118 | } else {
119 | tvTitle.setVisibility(View.GONE);
120 | }
121 | if (!TextUtils.isEmpty(strLeft)) {
122 | tvLeft.setText(strLeft);
123 | tvLeft.setVisibility(View.VISIBLE);
124 | } else {
125 | tvLeft.setVisibility(View.GONE);
126 | }
127 | if (!TextUtils.isEmpty(strRight)) {
128 | tvRight.setText(strRight);
129 | tvRight.setVisibility(View.VISIBLE);
130 | } else {
131 | tvRight.setVisibility(View.GONE);
132 | }
133 |
134 | if (resIdLeft == 0) {
135 | iconLeft.setVisibility(View.GONE);
136 | } else {
137 | iconLeft.setBackgroundResource(resIdLeft);
138 | iconLeft.setVisibility(View.VISIBLE);
139 | }
140 |
141 | if (resIdRight == 0) {
142 | iconRight.setVisibility(View.GONE);
143 | } else {
144 | iconRight.setBackgroundResource(resIdRight);
145 | iconRight.setVisibility(View.VISIBLE);
146 | }
147 |
148 | if (listener != null) {
149 | layLeft = findViewById(R.id.lay_actionbar_left);
150 | layRight = findViewById(R.id.lay_actionbar_right);
151 | layLeft.setOnClickListener(new View.OnClickListener() {
152 | @Override
153 | public void onClick(View v) {
154 | listener.onLeftClick();
155 | }
156 | });
157 | layRight.setOnClickListener(new View.OnClickListener() {
158 | @Override
159 | public void onClick(View v) {
160 | listener.onRightClick();
161 | }
162 | });
163 | }
164 | }
165 |
166 | }
167 |
--------------------------------------------------------------------------------
/app/src/main/java/com/yyh/status/key/widget/TranslucentScrollView.java:
--------------------------------------------------------------------------------
1 | package com.yyh.status.key.widget;
2 |
3 | import android.animation.ObjectAnimator;
4 | import android.animation.ValueAnimator;
5 | import android.content.Context;
6 | import android.graphics.Color;
7 | import android.support.annotation.ColorInt;
8 | import android.support.v4.graphics.ColorUtils;
9 | import android.util.AttributeSet;
10 | import android.util.Log;
11 | import android.view.MotionEvent;
12 | import android.view.View;
13 | import android.view.ViewGroup;
14 | import android.view.WindowManager;
15 | import android.widget.ScrollView;
16 |
17 | import com.yyh.status.key.R;
18 | import com.yyh.status.key.utils.SizeUtils;
19 |
20 |
21 | /**
22 | * 类功能描述:
23 | * Android沉浸式状态栏 + scrollView顶部伸缩 + actionBar渐变
24 | * 博客地址:http://blog.csdn.net/androidstarjack
25 | * 公众号:终端研发部
26 | * @author yuyahao
27 | * @version 1.0 修改时间: 修改备注:
28 | */
29 | public class TranslucentScrollView extends ScrollView {
30 |
31 | static final String TAG = "TranslucentScrollView";
32 |
33 | //伸缩视图
34 | private View zoomView;
35 | //伸缩视图初始高度
36 | private int zoomViewInitHeight = 0;
37 | // 记录首次按下位置
38 | private float mFirstPosition = 0;
39 | // 是否正在放大
40 | private Boolean mScaling = false;
41 |
42 | //渐变的视图
43 | private View transView;
44 | //渐变颜色
45 | private int transColor = Color.WHITE;
46 | //渐变开始位置
47 | private int transStartY = 50;
48 | //渐变结束位置
49 | private int transEndY = 300;
50 |
51 | //渐变开始默认位置,Y轴,50dp
52 | private final int DFT_TRANSSTARTY = 50;
53 | //渐变结束默认位置,Y轴,300dp
54 | private final int DFT_TRANSENDY = 300;
55 |
56 | private TranslucentScrollView.TranslucentChangedListener translucentChangedListener;
57 |
58 | public interface TranslucentChangedListener {
59 | /**
60 | * 透明度变化,取值范围0-255
61 | *
62 | * @param transAlpha
63 | */
64 | void onTranslucentChanged(int transAlpha);
65 | }
66 |
67 | public TranslucentScrollView(Context context) {
68 | super(context);
69 | }
70 |
71 | public TranslucentScrollView(Context context, AttributeSet attrs) {
72 | super(context, attrs);
73 | }
74 |
75 | public TranslucentScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
76 | super(context, attrs, defStyleAttr);
77 | }
78 |
79 | public void setTranslucentChangedListener(TranslucentScrollView.TranslucentChangedListener translucentChangedListener) {
80 | this.translucentChangedListener = translucentChangedListener;
81 | }
82 |
83 | /**
84 | * 设置伸缩视图
85 | *
86 | * @param zoomView
87 | */
88 | public void setPullZoomView(View zoomView) {
89 | this.zoomView = zoomView;
90 | zoomViewInitHeight = zoomView.getLayoutParams().height;
91 | if (zoomViewInitHeight == LayoutParams.MATCH_PARENT || zoomViewInitHeight == WindowManager.LayoutParams.WRAP_CONTENT) {
92 | zoomView.post(new Runnable() {
93 | @Override
94 | public void run() {
95 | zoomViewInitHeight = TranslucentScrollView.this.zoomView.getHeight();
96 | }
97 | });
98 | }
99 | }
100 |
101 | /**
102 | * 设置渐变视图
103 | *
104 | * @param transView 渐变的视图
105 | */
106 | public void setTransView(View transView) {
107 | setTransView(transView, getResources().getColor(R.color.colorPrimary), SizeUtils.dip2px(getContext(), DFT_TRANSSTARTY), SizeUtils.dip2px(getContext(), DFT_TRANSENDY));
108 | }
109 |
110 | /**
111 | * 设置渐变视图
112 | *
113 | * @param transView 渐变的视图
114 | * @param transColor 渐变颜色
115 | * @param transEndY 渐变结束位置
116 | */
117 | public void setTransView(View transView, @ColorInt int transColor, int transStartY, int transEndY) {
118 | this.transView = transView;
119 | //初始视图-透明
120 | this.transView.setBackgroundColor(ColorUtils.setAlphaComponent(transColor, 0));
121 | this.transStartY = transStartY;
122 | this.transEndY = transEndY;
123 | this.transColor = transColor;
124 | if (transStartY > transEndY) {
125 | throw new IllegalArgumentException("transStartY 不得大于 transEndY .. ");
126 | }
127 | }
128 |
129 | /**
130 | * 获取透明度
131 | *
132 | * @return
133 | */
134 | private int getTransAlpha() {
135 | float scrollY = getScrollY();
136 | if (transStartY != 0) {
137 | if (scrollY <= transStartY) {
138 | return 0;
139 | } else if (scrollY >= transEndY) {
140 | return 255;
141 | } else {
142 | return (int) ((scrollY - transStartY) / (transEndY - transStartY) * 255);
143 | }
144 | } else {
145 | if (scrollY >= transEndY) {
146 | return 255;
147 | }
148 | return (int) ((transEndY - scrollY) / transEndY * 255);
149 | }
150 | }
151 |
152 | /**
153 | * 重置ZoomView
154 | */
155 | private void resetZoomView() {
156 | final ViewGroup.LayoutParams lp = zoomView.getLayoutParams();
157 | final float h = zoomView.getLayoutParams().height;// ZoomView当前高度
158 |
159 | // 设置动画
160 | ValueAnimator anim = ObjectAnimator.ofFloat(0.0F, 1.0F).setDuration(200);
161 |
162 | anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
163 | @Override
164 | public void onAnimationUpdate(ValueAnimator animation) {
165 | float cVal = (Float) animation.getAnimatedValue();
166 | lp.height = (int) (h - (h - zoomViewInitHeight) * cVal);
167 | zoomView.setLayoutParams(lp);
168 | }
169 | });
170 | anim.start();
171 | }
172 |
173 | @Override
174 | protected void onScrollChanged(int l, int t, int oldl, int oldt) {
175 | super.onScrollChanged(l, t, oldl, oldt);
176 | int transAlpha = getTransAlpha();
177 |
178 | if (transView != null) {
179 | Log.d(TAG, "[onScrollChanged .. in ], 透明度 == " + transAlpha);
180 | transView.setBackgroundColor(ColorUtils.setAlphaComponent(transColor, transAlpha));
181 | }
182 | if (translucentChangedListener != null) {
183 | translucentChangedListener.onTranslucentChanged(transAlpha);
184 | }
185 | }
186 |
187 | @Override
188 | public boolean onTouchEvent(MotionEvent event) {
189 | if (zoomView != null) {
190 | ViewGroup.LayoutParams params = zoomView.getLayoutParams();
191 | switch (event.getAction()) {
192 | case MotionEvent.ACTION_UP:
193 | //手指离开后恢复图片
194 | mScaling = false;
195 | resetZoomView();
196 | break;
197 | case MotionEvent.ACTION_MOVE:
198 | if (!mScaling) {
199 | if (getScrollY() == 0) {
200 | mFirstPosition = event.getY();
201 | } else {
202 | break;
203 | }
204 | }
205 |
206 | int distance = (int) ((event.getY() - mFirstPosition) * 0.6);
207 | if (distance < 0) {
208 | break;
209 | }
210 | mScaling = true;
211 | params.height = zoomViewInitHeight + distance;
212 |
213 | Log.d(TAG, "params.height == " + params.height + ", zoomViewInitHeight == " + zoomViewInitHeight + ", distance == " + distance);
214 | zoomView.setLayoutParams(params);
215 | return true;
216 | }
217 | }
218 |
219 | return super.onTouchEvent(event);
220 | }
221 |
222 | }
223 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/actionbar_trans.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
18 |
19 |
24 |
25 |
33 |
34 |
45 |
46 |
47 |
53 |
54 |
61 |
62 |
70 |
71 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_actionbar.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
12 |
16 |
17 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
15 |
16 |
22 |
23 |
28 |
29 |
32 |
33 |
38 |
39 |
46 |
47 |
48 |
55 |
56 |
63 |
64 |
71 |
72 |
73 |
74 |
75 |
82 |
83 |
90 |
91 |
96 |
97 |
101 |
102 |
103 |
110 |
111 |
117 |
118 |
124 |
125 |
126 |
133 |
134 |
139 |
140 |
144 |
145 |
146 |
147 |
152 |
153 |
157 |
158 |
164 |
165 |
171 |
172 |
179 |
180 |
192 |
193 |
199 |
200 |
201 |
204 |
205 |
211 |
212 |
221 |
222 |
228 |
229 |
235 |
236 |
237 |
241 |
242 |
248 |
249 |
255 |
256 |
264 |
265 |
271 |
272 |
273 |
276 |
277 |
283 |
284 |
290 |
291 |
299 |
300 |
306 |
307 |
308 |
312 |
313 |
319 |
320 |
326 |
327 |
335 |
336 |
342 |
343 |
344 |
347 |
348 |
354 |
355 |
361 |
362 |
370 |
371 |
377 |
378 |
379 |
383 |
384 |
390 |
391 |
397 |
398 |
406 |
407 |
413 |
414 |
415 |
419 |
420 |
421 |
422 |
423 |
430 |
431 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/b72d93a1b308ad9305cd36050dbf453c.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/b72d93a1b308ad9305cd36050dbf453c.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/bg_avatar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/bg_avatar.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/bg_banner_my.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/bg_banner_my.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/dft_avatar.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/dft_avatar.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_address.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/ic_address.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_agent_my.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/ic_agent_my.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_consume_history.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/ic_consume_history.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_invite_my.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/ic_invite_my.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_left_light.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/ic_left_light.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_luck_my.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/ic_luck_my.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_right_gray.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/ic_right_gray.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_set_my.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/ic_set_my.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_shopcar_my.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/ic_shopcar_my.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_sign.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/ic_sign.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_teacher_my.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/ic_teacher_my.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_wallet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/ic_wallet.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/iv_my_docotor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxhdpi/iv_my_docotor.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v19/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | #3F51B5
5 | #303F9F
6 | #FF4081
7 |
8 | #fefefe
9 | #3c3c3c
10 | #00000000
11 | #f0eff4
12 | #888888
13 | #f0f0f0
14 | #c9c9c9
15 | #f12345
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 350dp
6 | 100dp
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | 渐变拉缩状态栏
3 | 总计:5000元
4 | 关注人数:300人
5 |
6 |
7 | 钱包
8 | 签到
9 | (今日已签到)
10 | 家庭地址
11 | 我的医院
12 | 我要学医
13 | 开始抽奖
14 | 邀请奖励
15 | 设置
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
13 |
19 |
20 |
26 |
27 |
32 |
33 |
38 |
39 |
44 |
45 |
50 |
51 |
52 |
53 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.2.2'
9 |
10 | // NOTE: Do not place your application dependencies here; they belong
11 | // in the individual module build.gradle files
12 | }
13 | }
14 |
15 | allprojects {
16 | repositories {
17 | jcenter()
18 | }
19 | }
20 |
21 | task clean(type: Delete) {
22 | delete rootProject.buildDir
23 | }
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codeGoogler/TranslucentScrollView/4b89c8af12d120a0d5302ab0d3d2b4ad997d0a15/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Mon Dec 28 10:00:20 PST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 |
2 | 最近需求要做一个拉缩渐变的状态栏,往上拉的时候,需要显示actionBar,这个过程是渐变的,顶部的图片背景能实现拉缩,并且还要实现状态栏沉浸式
3 |
4 | 效果如如下:
5 |
6 | 
7 |
8 | - 实现状态栏的透明化
9 | - 实现ScrollView的拉缩
10 | - 实现ActionBar的渐变
11 |
12 | ### 实现
13 | 1、至于试下实现ScrollView的拉缩这个效果很简单重写onTouchEvent方法,利用滑动的垂直方向的距离,然后在设置图片的大小
14 | ```
15 | ......
16 | case MotionEvent.ACTION_MOVE:
17 | if (!mScaling) {
18 | if (getScrollY() == 0) {
19 | mFirstPosition = event.getY();
20 | } else {
21 | break;
22 | }
23 | }
24 |
25 | int distance = (int) ((event.getY() - mFirstPosition) * 0.6);
26 | if (distance < 0) {
27 | break;
28 | }
29 | mScaling = true;
30 | params.height = zoomViewInitHeight + distance;
31 |
32 | Log.d(TAG, "params.height == " + params.height + ", zoomViewInitHeight == " + zoomViewInitHeight + ", distance == " + distance);
33 | zoomView.setLayoutParams(params);
34 | return true;
35 | ```
36 | **这里要注意的是**:在手指释放的时候需要进行恢复图片的高度
37 |
38 | 2、ActionBar的透明度很简单了,在onScrollChanged里进行操作即可
39 | ```
40 | @Override
41 | protected void onScrollChanged(int l, int t, int oldl, int oldt) {
42 | super.onScrollChanged(l, t, oldl, oldt);
43 | int transAlpha = getTransAlpha();
44 |
45 | if (transView != null) {
46 | Log.d(TAG, "[onScrollChanged .. in ], 透明度 == " + transAlpha);
47 | transView.setBackgroundColor(ColorUtils.setAlphaComponent(transColor, transAlpha));
48 | }
49 | if (translucentChangedListener != null) {
50 | translucentChangedListener.onTranslucentChanged(transAlpha);
51 | }
52 | }
53 |
54 | ```
55 |
56 | 3、至于沉浸式状态栏就很简单了,之前写过帖子
57 |
58 | - [你这样玩过android沉浸式状态栏吗—教你玩出新花样](http://mp.weixin.qq.com/s?__biz=MzI3OTU0MzI4MQ==&mid=2247484479&idx=1&sn=017393b284bc9f746006994a1499dfc8&chksm=eb4768a1dc30e1b7b736c8055a511fb3aea9cc186442ecb7979b15665b59c9cba33a41226a6f&scene=21#wechat_redirect)
59 |
60 | - [ Activity样式 、状态栏透明、屏幕亮度问题全面解析](http://mp.weixin.qq.com/s?__biz=MzI3OTU0MzI4MQ==&mid=2247484366&idx=1&sn=93c36500ee10081ce8e7d319beaf0bf0&chksm=eb476f50dc30e646c0796a2614dc698c83c9023b800c3d7d80acdd09f1f9eab8f98649b8e0b7&scene=21#wechat_redirect)
61 |
62 |
63 | 这里我简单的封装了一些工具类
64 | ####
65 |
66 | ```
67 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//5.0及以上
68 | View decorView = getWindow().getDecorView();
69 | int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
70 | | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
71 | decorView.setSystemUiVisibility(option);
72 | getWindow().setStatusBarColor(Color.TRANSPARENT);
73 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {//4.4到5.0
74 | WindowManager.LayoutParams localLayoutParams = getWindow().getAttributes();
75 | localLayoutParams.flags = (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | localLayoutParams.flags);
76 | }
77 | ```
78 |
79 | 在相应的Activity或基类执行这段代码就ok了。
80 |
81 | 可见在4.4到5.0的系统、5.0及以上系统的处理方式有所不同
82 |
83 | 除了这种代码修改额方式外,还可以通过主题来修改,需要在values、values-v19、values-v21目录下分别创建相应的主题:
84 |
85 | ```
86 | //values
87 | //values-v19//values-v21
96 | ```
97 |
98 | 给相应Activity或Application设置该主题就ok了。
99 |
100 | 两种方式根据需求选择就好了,到这里我们就完成了第一步,将状态栏透明化了。
101 |
102 | 完成了第一步,我们开始给状态栏加上想要的色彩吧!
103 |
104 | 在values、values-v19目录添加如下尺寸:
105 |
106 | ```
107 | //values0dp//values-v1925dp
108 | ```
109 |
110 | 关于25dp,在有些系统上可能有误差,这里不做讨论!
111 |
112 | 2.1 页面顶部使用Toolbar(或自定义title) 一般情况状态栏的颜色和Toolbar的颜色相同,既然状态栏透明化后,布局页面延伸到了状态栏,何不给Toolbar加上一个状态栏高度的顶部padding呢:
113 |
114 | ```
115 |
122 | ```
123 |
124 | 效果图下:
125 |
126 | 
127 |
128 |
129 | 
130 |
131 | [最新2017(Android)面试题级答案(精选版)](https://mp.weixin.qq.com/s/C-S8Gs5wfW9OOIS_UJBzqw)
132 |
133 | [“你还有什么事想问”——如何回答面试官的问题](http://mp.weixin.qq.com/s?__biz=MzI3OTU0MzI4MQ==&mid=2247484208&idx=1&sn=9f5292b50fd2198e13e4963e5ed2973d&chksm=eb476faedc30e6b8889106a9dac9ea3ea17da8e93fd32fbc6876ef4711537ccb97261e06ed8f&scene=21#wechat_redirect)
134 |
135 | [Android 图片选择到裁剪之步步深坑](http://mp.weixin.qq.com/s?__biz=MzI3OTU0MzI4MQ==&mid=2247484873&idx=1&sn=ff61bb74db725970d939a7b40ab0e06e&chksm=eb476957dc30e0417f04e9463949482d52ec30e181d38029f0dd18388b58448d067404678839&scene=21#wechat_redirect)
136 |
137 | >博客地址:
138 | >
139 | > http://www.jianshu.com/p/05aa5329c3d3
140 |
141 | > 项目地址:
142 | >
143 | > https://github.com/androidstarjack/TranslucentScrollView
144 |
145 |
146 | #### 相信自己,没有做不到的,只有想不到的
147 |
148 | 如果你觉得此文对您有所帮助, 欢迎加入微信公众号:终端研发部
149 |
150 | 
151 |
152 |
153 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------