├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── hankkin │ │ └── gradationtitlebar │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── hankkin │ │ │ └── gradationtitlebar │ │ │ ├── BannerActivity.java │ │ │ ├── MainActivity.java │ │ │ └── QQSpeakActivity.java │ └── res │ │ ├── drawable-xhdpi │ │ ├── banner1.png │ │ ├── banner2.png │ │ ├── banner3.png │ │ └── banner4.png │ │ ├── layout │ │ ├── activity_banner.xml │ │ ├── activity_main.xml │ │ └── activity_qqspeak.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ ├── styleable.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── hankkin │ └── gradationtitlebar │ └── ExampleUnitTest.java ├── build.gradle ├── gradationscroll ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── hankkin │ │ └── gradationscroll │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── hankkin │ │ │ └── gradationscroll │ │ │ ├── GradationScrollView.java │ │ │ ├── MaterialIndicator.java │ │ │ ├── NoScrollListview.java │ │ │ └── StatusBarUtil.java │ └── res │ │ └── values │ │ ├── strings.xml │ │ ├── styleable.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── hankkin │ └── gradationscroll │ └── ExampleUnitTest.java ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── 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 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | GradationTitleBar -------------------------------------------------------------------------------- /.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/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 25 | 26 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GradationTitleBar 2 | 仿QQ空间标题栏渐变 3 | ###look at the screenshot: 4 | 5 | 高仿微信群聊头像 6 | 7 | ###xml 8 | ```java 9 | 10 | 15 | 16 | 21 | 25 | 31 | 35 | 36 | 37 | 38 | 48 | 49 | ``` 50 | ###获取顶部图片高度后,设置滚动监听 51 | ```java 52 | private void initListeners() { 53 | 54 | ViewTreeObserver vto = ivBanner.getViewTreeObserver(); 55 | vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 56 | @Override 57 | public void onGlobalLayout() { 58 | textView.getViewTreeObserver().removeGlobalOnLayoutListener( 59 | this); 60 | height = ivBanner.getHeight(); 61 | 62 | scrollView.setScrollViewListener(QQSpeakActivity.this); 63 | } 64 | }); 65 | } 66 | ``` 67 | ###滑动监听,设置透明度 68 | ```java 69 | @Override 70 | public void onScrollChanged(GradationScrollView scrollView, int x, int y, 71 | int oldx, int oldy) { 72 | // TODO Auto-generated method stub 73 | if (y <= 0) { //设置标题的背景颜色 74 | textView.setBackgroundColor(Color.argb((int) 0, 144,151,166)); 75 | } else if (y > 0 && y <= height) { //滑动距离小于banner图的高度时,设置背景和字体颜色颜色透明度渐变 76 | float scale = (float) y / height; 77 | float alpha = (255 * scale); 78 | textView.setTextColor(Color.argb((int) alpha, 255,255,255)); 79 | textView.setBackgroundColor(Color.argb((int) alpha, 144,151,166)); 80 | } else { //滑动到banner下面设置普通颜色 81 | textView.setBackgroundColor(Color.argb((int) 255, 144,151,166)); 82 | } 83 | } 84 | ``` 85 | ###博客地址 86 | --------------------------- 87 | 88 | 89 | ###License 90 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "com.hankkin.gradationtitlebar" 9 | minSdkVersion 15 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 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(include: ['*.jar'], dir: 'libs') 24 | testCompile 'junit:junit:4.12' 25 | compile 'com.android.support:appcompat-v7:23.4.0' 26 | compile project(':gradationscroll') 27 | } 28 | -------------------------------------------------------------------------------- /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 /Users/Hankkin/Library/Android/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/androidTest/java/com/hankkin/gradationtitlebar/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.hankkin.gradationtitlebar; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/java/com/hankkin/gradationtitlebar/BannerActivity.java: -------------------------------------------------------------------------------- 1 | package com.hankkin.gradationtitlebar; 2 | 3 | import android.graphics.Color; 4 | import android.support.v4.view.PagerAdapter; 5 | import android.support.v4.view.ViewPager; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.os.Bundle; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | import android.view.ViewTreeObserver; 11 | import android.view.Window; 12 | import android.widget.ArrayAdapter; 13 | import android.widget.ImageView; 14 | import android.widget.ListView; 15 | import android.widget.TextView; 16 | 17 | import com.hankkin.gradationscroll.GradationScrollView; 18 | import com.hankkin.gradationscroll.MaterialIndicator; 19 | import com.hankkin.gradationscroll.StatusBarUtil; 20 | 21 | public class BannerActivity extends AppCompatActivity implements GradationScrollView.ScrollViewListener { 22 | private GradationScrollView scrollView; 23 | private ListView listView; 24 | private TextView textView; 25 | private int imageHeight; 26 | private ViewPager viewPager; 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | getWindow().requestFeature(Window.FEATURE_NO_TITLE); 31 | StatusBarUtil.setImgTransparent(this); 32 | setContentView(R.layout.activity_banner); 33 | 34 | scrollView = (GradationScrollView) findViewById(R.id.scrollview); 35 | listView = (ListView) findViewById(R.id.listview); 36 | textView = (TextView) findViewById(R.id.textview); 37 | viewPager = (ViewPager) findViewById(R.id.viewPager); 38 | 39 | viewPager.setFocusable(true); 40 | viewPager.setFocusableInTouchMode(true); 41 | viewPager.requestFocus(); 42 | 43 | MaterialIndicator indicator = (MaterialIndicator) findViewById(R.id.indicator); 44 | ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager); 45 | viewPager.setAdapter(new MyPagerAdapter()); 46 | viewPager.addOnPageChangeListener(indicator); 47 | indicator.setAdapter(viewPager.getAdapter()); 48 | 49 | initListeners(); 50 | initData(); 51 | } 52 | 53 | /** 54 | * viewpager适配器 55 | */ 56 | private class MyPagerAdapter extends PagerAdapter { 57 | public int[] drawables = {R.drawable.banner1 58 | ,R.drawable.banner2,R.drawable.banner3,R.drawable.banner4}; 59 | @Override 60 | public int getCount() { 61 | return 4; 62 | } 63 | 64 | @Override 65 | public boolean isViewFromObject(View view, Object object) { 66 | return object == view; 67 | } 68 | 69 | @Override 70 | public Object instantiateItem(ViewGroup container, int position) { 71 | ImageView view = new ImageView(container.getContext()); 72 | view.setImageResource(drawables[position]); 73 | view.setScaleType(ImageView.ScaleType.FIT_XY); 74 | container.addView(view); 75 | return view; 76 | } 77 | 78 | @Override 79 | public void destroyItem(ViewGroup container, int position, Object object) { 80 | container.removeView(((View) object)); 81 | } 82 | } 83 | 84 | /** 85 | * 获取顶部图片高度后,设置滚动监听 86 | */ 87 | private void initListeners() { 88 | 89 | ViewTreeObserver vto = viewPager.getViewTreeObserver(); 90 | vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 91 | @Override 92 | public void onGlobalLayout() { 93 | viewPager.getViewTreeObserver().removeGlobalOnLayoutListener( 94 | this); 95 | imageHeight = viewPager.getHeight(); 96 | 97 | scrollView.setScrollViewListener(BannerActivity.this); 98 | } 99 | }); 100 | } 101 | 102 | 103 | 104 | private void initData() { 105 | ArrayAdapter adapter = new ArrayAdapter(BannerActivity.this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.data)); 106 | listView.setAdapter(adapter); 107 | } 108 | 109 | 110 | /** 111 | * 滑动监听 112 | * @param scrollView 113 | * @param x 114 | * @param y 115 | * @param oldx 116 | * @param oldy 117 | */ 118 | @Override 119 | public void onScrollChanged(GradationScrollView scrollView, int x, int y, 120 | int oldx, int oldy) { 121 | // TODO Auto-generated method stub 122 | if (y <= 0) { //设置标题的背景颜色 123 | textView.setBackgroundColor(Color.argb((int) 0, 144,151,166)); 124 | } else if (y > 0 && y <= imageHeight) { //滑动距离小于banner图的高度时,设置背景和字体颜色颜色透明度渐变 125 | float scale = (float) y / imageHeight; 126 | float alpha = (255 * scale); 127 | textView.setTextColor(Color.argb((int) alpha, 255,255,255)); 128 | textView.setBackgroundColor(Color.argb((int) alpha, 144,151,166)); 129 | } else { //滑动到banner下面设置普通颜色 130 | textView.setBackgroundColor(Color.argb((int) 255, 144,151,166)); 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /app/src/main/java/com/hankkin/gradationtitlebar/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.hankkin.gradationtitlebar; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.view.View; 7 | import android.widget.Button; 8 | 9 | public class MainActivity extends AppCompatActivity{ 10 | 11 | Button btnQQ; 12 | Button btnBanner; 13 | 14 | @Override 15 | protected void onCreate(Bundle savedInstanceState) { 16 | super.onCreate(savedInstanceState); 17 | 18 | setContentView(R.layout.activity_main); 19 | 20 | btnQQ = (Button) findViewById(R.id.btn_qq); 21 | btnBanner = (Button) findViewById(R.id.btn_banner); 22 | 23 | btnQQ.setOnClickListener(new View.OnClickListener() { 24 | @Override 25 | public void onClick(View v) { 26 | Intent intent = new Intent(MainActivity.this,QQSpeakActivity.class); 27 | startActivity(intent); 28 | } 29 | }); 30 | 31 | btnBanner.setOnClickListener(new View.OnClickListener() { 32 | @Override 33 | public void onClick(View v) { 34 | Intent intent = new Intent(MainActivity.this,BannerActivity.class); 35 | startActivity(intent); 36 | } 37 | }); 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /app/src/main/java/com/hankkin/gradationtitlebar/QQSpeakActivity.java: -------------------------------------------------------------------------------- 1 | package com.hankkin.gradationtitlebar; 2 | 3 | import android.graphics.Color; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.ViewTreeObserver; 7 | import android.view.Window; 8 | import android.widget.ArrayAdapter; 9 | import android.widget.ImageView; 10 | import android.widget.ListView; 11 | import android.widget.TextView; 12 | 13 | import com.hankkin.gradationscroll.GradationScrollView; 14 | import com.hankkin.gradationscroll.StatusBarUtil; 15 | 16 | public class QQSpeakActivity extends AppCompatActivity implements GradationScrollView.ScrollViewListener{ 17 | private GradationScrollView scrollView; 18 | 19 | private ListView listView; 20 | 21 | private TextView textView; 22 | private int height; 23 | private ImageView ivBanner; 24 | 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | getWindow().requestFeature(Window.FEATURE_NO_TITLE); 29 | StatusBarUtil.setImgTransparent(this); 30 | setContentView(R.layout.activity_qqspeak); 31 | 32 | scrollView = (GradationScrollView) findViewById(R.id.scrollview); 33 | listView = (ListView) findViewById(R.id.listview); 34 | textView = (TextView) findViewById(R.id.textview); 35 | ivBanner = (ImageView) findViewById(R.id.iv_banner); 36 | 37 | ivBanner.setFocusable(true); 38 | ivBanner.setFocusableInTouchMode(true); 39 | ivBanner.requestFocus(); 40 | 41 | initListeners(); 42 | initData(); 43 | } 44 | 45 | /** 46 | * 获取顶部图片高度后,设置滚动监听 47 | */ 48 | private void initListeners() { 49 | 50 | ViewTreeObserver vto = ivBanner.getViewTreeObserver(); 51 | vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { 52 | @Override 53 | public void onGlobalLayout() { 54 | textView.getViewTreeObserver().removeGlobalOnLayoutListener( 55 | this); 56 | height = ivBanner.getHeight(); 57 | 58 | scrollView.setScrollViewListener(QQSpeakActivity.this); 59 | } 60 | }); 61 | } 62 | 63 | 64 | 65 | private void initData() { 66 | ArrayAdapter adapter = new ArrayAdapter(QQSpeakActivity.this, android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.data)); 67 | listView.setAdapter(adapter); 68 | } 69 | 70 | 71 | /** 72 | * 滑动监听 73 | * @param scrollView 74 | * @param x 75 | * @param y 76 | * @param oldx 77 | * @param oldy 78 | */ 79 | @Override 80 | public void onScrollChanged(GradationScrollView scrollView, int x, int y, 81 | int oldx, int oldy) { 82 | // TODO Auto-generated method stub 83 | if (y <= 0) { //设置标题的背景颜色 84 | textView.setBackgroundColor(Color.argb((int) 0, 144,151,166)); 85 | } else if (y > 0 && y <= height) { //滑动距离小于banner图的高度时,设置背景和字体颜色颜色透明度渐变 86 | float scale = (float) y / height; 87 | float alpha = (255 * scale); 88 | textView.setTextColor(Color.argb((int) alpha, 255,255,255)); 89 | textView.setBackgroundColor(Color.argb((int) alpha, 144,151,166)); 90 | } else { //滑动到banner下面设置普通颜色 91 | textView.setBackgroundColor(Color.argb((int) 255, 144,151,166)); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/banner1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hankkin/GradationTitleBar/edb820965d82a1db379d915f10bee996f11fda8f/app/src/main/res/drawable-xhdpi/banner1.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/banner2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hankkin/GradationTitleBar/edb820965d82a1db379d915f10bee996f11fda8f/app/src/main/res/drawable-xhdpi/banner2.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/banner3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hankkin/GradationTitleBar/edb820965d82a1db379d915f10bee996f11fda8f/app/src/main/res/drawable-xhdpi/banner3.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/banner4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Hankkin/GradationTitleBar/edb820965d82a1db379d915f10bee996f11fda8f/app/src/main/res/drawable-xhdpi/banner4.png -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_banner.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 14 | 15 | 19 | 20 | 25 | 26 | 36 | 37 | 41 | 42 | 43 | 44 | 45 | 55 | 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 |