第三方开源库:nineoldandroids右弹出有动画
2016-04-15 17:51
513 查看
右弹出无动画特效和有特效2种
效果图:
1 无动画
思路:
主布局中有水平排列2个布局,用权重表示,weight=1,width=0dp,其中右侧的默认隐藏,
点击“显示侧拉”,右侧显示,在点击,右侧消失
布局:
activity代码
源码;http://download.csdn.net/detail/ss1168805219/9492492
2 listView和LinearLayout都要设置valueAnimator
布局
主要代码:
源码:http://download.csdn.net/detail/ss1168805219/9492511
ViewHelper.setScaleY(holder.itemView, 0.3f);
ViewPropertyAnimator.animate(holder.itemView).scaleXBy(0.7f)//by:比上一步的值增加了几倍 ,原来是0.5,增加0.5,还是1
.scaleYBy(0.7f)
// .scaleX(1.0f)//还原正常大小
// .scaleY(1.0f)//
.setInterpolator(new OvershootInterpolator())//默认也是这个
.setDuration(500).start();
效果图:
无动画: 瞬间弹出 有动画:时长:500ms
1 无动画
思路:
主布局中有水平排列2个布局,用权重表示,weight=1,width=0dp,其中右侧的默认隐藏,
点击“显示侧拉”,右侧显示,在点击,右侧消失
布局:
<LinearLayout 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:orientation="vertical" tools:context=".MainActivity" > <TextView android:id="@+id/tv_title" android:layout_width="match_parent" android:layout_height="30dp" android:background="#33666666" android:text="显示侧拉" android:gravity="center"/> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <ListView android:id="@+id/listview" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:dividerHeight="5dp" > </ListView> <LinearLayout android:id="@+id/layout_right" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" android:background="#0084ff" android:visibility="gone" > <TextView android:layout_width="match_parent" android:layout_height="match_parent" android:text="textView" /> </LinearLayout> </LinearLayout> </LinearLayout>
activity代码
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (ListView) findViewById(R.id.listview); listView.setAdapter(new LeftAdapter(this)); layout_right = (LinearLayout) findViewById(R.id.layout_right); tv_title = (TextView) findViewById(R.id.tv_title); //没有动画效果 tv_title.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (isOpen) { layout_right.setVisibility(View.GONE); isOpen = false; } else { layout_right.setVisibility(View.VISIBLE); isOpen = true; } } }); }
源码;http://download.csdn.net/detail/ss1168805219/9492492
有动画
1 导入nineoldandroids-2.4.0.jar,2 listView和LinearLayout都要设置valueAnimator
布局
<LinearLayout 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:orientation="vertical" tools:context=".MainActivity" > <TextView android:id="@+id/tv_title" android:layout_width="match_parent" android:layout_height="30dp" android:background="#33666666" android:gravity="center" android:text="显示侧拉" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" > <ListView android:id="@+id/listview" android:layout_width="match_parent" android:layout_height="match_parent" android:dividerHeight="5dp" > </ListView> <LinearLayout android:id="@+id/layout_right" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#0084ff" > <TextView android:id="@+id/tv_right" android:layout_width="wrap_content" android:layout_height="match_parent" android:text="textView" /> </LinearLayout> </LinearLayout> </LinearLayout>
主要代码:
screenWidth = getWindowManager().getDefaultDisplay().getWidth();//获取屏幕的宽 tv_title.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (isOpen) {//设置ValueAnimator值的变化范围 animator =ValueAnimator.ofInt(screenWidth/2,0); animator2 =ValueAnimator.ofInt(screenWidth/2,screenWidth); isOpen = false; } else { animator =ValueAnimator.ofInt(0,screenWidth/2); animator2 =ValueAnimator.ofInt(screenWidth,screenWidth/2); isOpen = true; } //listView的动画 animator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int width = (Integer) valueAnimator.getAnimatedValue();//获取变化中的值 layout_right.getLayoutParams().width = width; layout_right.requestLayout();//让width重新生效 } }); animator.setDuration(500).start();//开启动画 //有侧拉栏的动画 animator2.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int width = (Integer) valueAnimator.getAnimatedValue(); listView.getLayoutParams().width = width; listView.requestLayout(); } }); animator2.setDuration(500).start(); } });
源码:http://download.csdn.net/detail/ss1168805219/9492511
其它
ViewHelper.setScaleX(holder.itemView, 0.3f);ViewHelper.setScaleY(holder.itemView, 0.3f);
ViewPropertyAnimator.animate(holder.itemView).scaleXBy(0.7f)//by:比上一步的值增加了几倍 ,原来是0.5,增加0.5,还是1
.scaleYBy(0.7f)
// .scaleX(1.0f)//还原正常大小
// .scaleY(1.0f)//
.setInterpolator(new OvershootInterpolator())//默认也是这个
.setDuration(500).start();
相关文章推荐
- Android Studio导入工程的正确姿势
- Android monkey测试
- android MonkeyRunner的使用
- 【Android】studio更新时,不小心点了ignore(忽略),看我肿么破
- Android5.0+(CollapsingToolbarLayout)
- Android 用MediaCodec实现视频硬解码
- Android 监听电源键事件处理
- Android服务——Service
- Android服务——Service
- android的消息处理机制(图+源码分析)——Looper,Handler,Message
- Android知识梳理之BroadcastReceiver整理
- Android系统中拍照功能的调用
- Animation基本的几种使用方法
- Android Studio 比较好的资源收集
- Android中通过EventBus传递消息数据
- 查看android sqlite数据库常用操作
- WIFI无线调试android真机开发
- android SDK 代理
- Android知识梳理之Service整理
- android 6.0权限处理