第三方开源库:nineoldandroids右弹出有动画

右弹出无动画特效和有特效2种

效果图:

无动画:       瞬间弹出                                                                                                                             有动画:时长: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();


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值