android 仿QQ好友动态 title滑动渐变
来源:互联网 发布:iphone连接电脑软件 编辑:程序博客网 时间:2024/06/08 10:13
最近QQ更新了qq空间消息列表。天天动听也使用了那效果。而且越来越多的android应用都在使用,咱们不能落后啊!
得紧跟时代的步伐,不然就out了。 看起来不错分享下咯!
首先贴一下效果图,因为gif动态图片不懂怎么搞。下次一定改进。
贴下代码先:
自定义了滑动时背景颜色渐变
- package com.seven.fadingdemo;
- import com.seven.fadingactionbardemo.R;
- import android.annotation.SuppressLint;
- import android.content.Context;
- import android.graphics.drawable.Drawable;
- import android.util.AttributeSet;
- import android.view.MotionEvent;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- /**
- * 定义的控件布局
- *
- * @author seven2729
- */
- public class FadingScrollView extends LinearLayout {
- private LinearLayout mActionBar;
- private Drawable mBgDrawable;
- private ImageView fadingBar;// title渐变的控件
- private int fadingHeight; // 可隐藏的控件高度
- private int oldY;
- private int fadingOffset;
- public static final int ALPHA_START = 20;
- public static final int ALPHA_END = 255;
- public FadingScrollView(Context context) {
- this(context, null);
- }
- public FadingScrollView(Context context, AttributeSet attrs) {
- this(context, attrs, 0);
- }
- @SuppressLint("NewApi")
- public FadingScrollView(Context context, AttributeSet attrs,
- int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- setOrientation(VERTICAL);
- }
- @Override
- protected void onFinishInflate() {
- super.onFinishInflate();
- fadingBar = (ImageView) findViewById(R.id.fading_bar);
- }
- @Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- fadingHeight = fadingBar.getMeasuredHeight() - fadingOffset;// title渐变的控件距离
- }
- @SuppressLint("ClickableViewAccessibility")
- @Override
- public boolean onTouchEvent(MotionEvent ev) {
- switch (ev.getAction()) {
- case MotionEvent.ACTION_DOWN:
- oldY = (int) ev.getY();
- break;
- case MotionEvent.ACTION_MOVE:
- int scrollY = getScrollY();
- int y = (int) ev.getY();
- int deltaY = y - oldY;
- int willScrollY = scrollY - deltaY;
- if (willScrollY > fadingHeight)
- {// 不做操作颜色保持不变
- // willScrollY = fadingHeight;
- }
- else
- {// 颜色渐变
- updateActionBarAlpha(willScrollY * (ALPHA_END - ALPHA_START)
- / fadingHeight + ALPHA_START);
- }
- if (willScrollY < 0) {
- willScrollY = 0;
- }
- scrollTo(0, willScrollY);
- oldY = y;
- break;
- case MotionEvent.ACTION_UP:
- break;
- }
- return true;
- }
- public void bindingActionBar(LinearLayout actionBar) {
- mActionBar = actionBar;
- }
- @SuppressWarnings("deprecation")
- public void setActionBarBgDrawable(Drawable bgDrawable) {
- if (mActionBar == null) {
- try {
- throw new Exception(
- "Please try to binding the actionBar before set it's background.");
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- mBgDrawable = bgDrawable;
- mBgDrawable.setAlpha(ALPHA_START);
- mActionBar.setBackgroundDrawable(mBgDrawable);
- }
- @SuppressWarnings("deprecation")
- public void setActionBarAlpha(int alpha) throws Exception {
- if (mActionBar == null || mBgDrawable == null) {
- throw new Exception(
- "acitonBar is not binding or bgDrawable is not set.");
- }
- mBgDrawable.setAlpha(alpha);
- mActionBar.setBackgroundDrawable(mBgDrawable);
- }
- void updateActionBarAlpha(int alpha) {
- try {
- setActionBarAlpha(alpha);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void setFadingOffset(int height) {
- fadingOffset = height;
- }
- }
然后就是代码的使用了,根据自己的需要设置大小或者颜色。
- package com.seven.fadingdemo;
- import com.seven.fadingactionbardemo.R;
- import android.annotation.SuppressLint;
- import android.app.Activity;
- import android.graphics.drawable.ColorDrawable;
- import android.os.Bundle;
- import android.widget.LinearLayout;
- /**
- * 主页展示页面
- *
- * @author seven2729
- */
- public class MainActivity extends Activity {
- private LinearLayout mLayout;
- private FadingScrollView fadingScrollView;// 自定义滑动布局
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.activity_main);
- fadingScrollView = (FadingScrollView) findViewById(R.id.root);
- initLinearLayout();
- }
- /**
- * 布局初始化
- */
- @SuppressLint({ "Recycle", "InlinedApi" })
- void initLinearLayout() {
- //初始化fadingScrollView的一些信息
- mLayout = (LinearLayout) findViewById(R.id.lyout_title);
- ColorDrawable bgDrawable = new ColorDrawable(getResources().getColor(
- R.color.color_blue));
- fadingScrollView.bindingActionBar(mLayout);// 设置渐变布局
- fadingScrollView.setActionBarBgDrawable(bgDrawable);// 设置渐变颜色
- }
- }
颜色值的代码:
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <color name="white">#FFFFFF</color>
- <color name="black">#000000</color>
- <color name="transparent">#00000000</color>
- <color name="color_blue">#50BDFB</color>
- </resources>
因为最近有在研究,所以找点资料自己修改了。改成自己需要的
如有需要可以 下载源码
如源码有偏差请根据博文修改!
欢迎转载,转载请注明出处:http://blog.csdn.net/seven2729/article/details/48372851
0 0
- android 仿QQ好友动态 title滑动渐变
- Android:仿手机QQ好友动态的ListView
- Android:仿手机QQ好友动态的ListView
- ANDROID 动态添加的listView,仿QQ滑动删除
- Android 高仿QQ 好友分组列表
- Android 高仿QQ 好友分组列表
- Android 高仿QQ 好友分组列表
- Android 高仿QQ 好友分组列表
- Android studio仿QQ好友列表
- Android 仿QQ 滑动删除
- Android自定义控件实战仿新浪微博QQ好友动态滑到底部自动加载
- 仿QQ好友列表
- Android--仿QQ空间动态页(继续拖动查看详情)及标题栏渐变
- android页面滑动时,顶部title背景渐变的实现
- Android 高仿QQ 界面滑动效果
- Android 高仿QQ 界面滑动效果
- Android 高仿QQ 界面滑动效果
- Android开发仿QQ聊天滑动listview
- 八大种必知排序算法(三) 归并排序算法、堆排序算法详解
- JNI 与 NDK
- Timer和TimerTask在Android中的用法
- Android:继承ImageView 实现 圆角图片,圆形图片处理。
- VS2013导出的环境不能导入到VS2012中【解决方案】
- android 仿QQ好友动态 title滑动渐变
- Python基础学习笔记之二
- Linux apache+php+mysql
- 八大种必知排序算法(三) 归并排序算法、堆排序算法详解 (续)
- submit禁止提交的几种方式
- qml学习------------信号和槽的连接
- Docker 的应用场景在哪里?
- Cocos2dx-jsb 3.x 精灵构建过程浅析(2):
- android日志保存