实现加号的延伸

布局 这里没有引用自定义view 自己引用一下

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!--收藏图片-->
    <ImageView
        android:layout_alignParentRight="true"
        android:id="@+id/like"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:src="@mipmap/report1"
        android:scaleType="centerCrop"/>
    <!--收藏的文字-->
    <TextView
        android:id="@+id/like_text"
        android:layout_alignParentRight="true"
        android:layout_marginTop="48dp"
        android:layout_marginRight="13dp"
        android:textSize="13dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />


    <!--分享的图片-->
    <ImageView
        android:layout_alignParentRight="true"
        android:id="@+id/care_of"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:src="@mipmap/copylink1"
        android:scaleType="centerCrop"/>
    <!--分享的文字-->
    <TextView
        android:id="@+id/care_of_text"
        android:layout_alignParentRight="true"
        android:layout_marginTop="48dp"
        android:layout_marginRight="13dp"
        android:textSize="13dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <!--评论的图片-->
    <ImageView
        android:layout_alignParentRight="true"
        android:id="@+id/commend"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:src="@mipmap/shiled1"
        android:scaleType="centerCrop"/>
    <!--评论的文字-->
    <TextView
        android:id="@+id/commend_text"
        android:layout_alignParentRight="true"
        android:layout_marginTop="48dp"
        android:layout_marginRight="13dp"
        android:textSize="13dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <ImageView
        android:layout_alignParentRight="true"
        android:id="@+id/open_option"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:src="@mipmap/icon_open"
        android:scaleType="centerCrop"/>
</RelativeLayout>

实现


public class Myjia extends RelativeLayout implements Vi
ew.OnClickListener {

    private ImageView like;
    private ImageView care_of;
    private ImageView commend;
    private ImageView open_option;
    private boolean opofpc = true;
    private TextView like_text;
    private TextView care_of_text;
    private TextView commend_text;
    public Myjia(Context context) {
        this(context,null);
    }

    public Myjia(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public Myjia(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        View view = View.inflate(context, R.layout.layout_jia, this);
        initView();
    }

    private void initView() {
        like = (ImageView) findViewById(R.id.like);
        like.setOnClickListener(this);
        care_of = (ImageView) findViewById(R.id.care_of);
        care_of.setOnClickListener(this);
        commend = (ImageView) findViewById(R.id.commend);
        commend.setOnClickListener(this);
        open_option = (ImageView) findViewById(R.id.open_option);
        open_option.setOnClickListener(this);
        like_text = (TextView) findViewById(R.id.like_text);
        like_text.setOnClickListener(this);
        care_of_text = (TextView) findViewById(R.id.care_of_text);
        care_of_text.setOnClickListener(this);
        commend_text = (TextView) findViewById(R.id.commend_text);
        commend_text.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        //判断点击的哪个按钮
        switch (v.getId()) {
            //点击最外边的按钮图片,展开
            case R.id.open_option:
                open_option();
                Translationy();
                break;
            case R.id.like:
                break;
            case R.id.care_of:
                break;
            case R.id.commend:
                break;
            default:

                break;
        }
    }

    //移动
    private void Translationy() {
        //开始的


    }

    //展开
    private void open_option() {
        if (opofpc) {
            //更换图片
            open_option.setImageResource(R.mipmap.icon_packup);
            //设置打开收藏展开的位移
            ObjectAnimator.ofFloat(like, "translationX", 0F, -100F).setDuration(1000).start();//X轴平移旋转

            //赋值
            like_text.setText("分享");
            //设置打开收藏选项的文字平移
            ObjectAnimator.ofFloat(like_text, "translationX", 0F, -170F).setDuration(1000).start();//X轴平移旋转
            //设置打开收藏的旋转的动画
            ObjectAnimator.ofFloat(like, "rotation", 0F, 360F).setDuration(1000).start();//360度旋转

            //设置打开分享展开的位移
            ObjectAnimator.ofFloat(care_of, "translationX", 0F, -200F).setDuration(1000).start();//X轴平移旋转

            //赋值
            care_of_text.setText("复制链接");
            //设置打开分享选项的文字平移
            ObjectAnimator.ofFloat(care_of_text, "translationX", 0F, -250F).setDuration(1000).start();//X轴平移旋转
            //设置打开分享的旋转的动画
            ObjectAnimator.ofFloat(care_of, "rotation", 0F, 720F).setDuration(1000).start();//720度旋转

            //设置打开评论展开的位移
            ObjectAnimator.ofFloat(commend, "translationX", 0F, -300F).setDuration(1000).start();//X轴平移旋转
            //赋值
            commend_text.setText("屏蔽");
            //设置打开评论选项的文字平移
            ObjectAnimator.ofFloat(commend_text, "translationX", 0F, -70F).setDuration(1000).start();//X轴平移旋转
            //设置打开评论的旋转的动画
            ObjectAnimator.ofFloat(commend, "rotation", 0F, 1080F).setDuration(1000).start();//1080度旋转


            opofpc = false;
        } else {
            //收起的图片
            open_option.setImageResource(R.mipmap.icon_open);
            //设置收起收藏的位移
            ObjectAnimator.ofFloat(like, "translationX", -90F, 0F).setDuration(1000).start();//X轴平移旋转
            //设置收起收藏选项的文字平移
            ObjectAnimator.ofFloat(like_text, "translationX", -70F, 0F).setDuration(1000).start();//X轴平移旋转
            //赋值
            like_text.setText("");

            //设置收起收藏旋转动画
            ObjectAnimator.ofFloat(like, "rotation", -360F, 0F).setDuration(1000).start();//360度旋转

            //设置收起评论的位移
            ObjectAnimator.ofFloat(care_of, "translationX", -180F, 0F).setDuration(1000).start();//X轴平移旋转
            //设置收起分享选项的文字平移
            ObjectAnimator.ofFloat(care_of_text, "translationX", -145F, 0F).setDuration(1000).start();//X轴平移旋转
            //赋值
            care_of_text.setText("");
            //设置收起评论旋转动画
            ObjectAnimator.ofFloat(care_of, "rotation", -720F, 0F).setDuration(1000).start();//720度旋转

            //设置收起评论的位移
            ObjectAnimator.ofFloat(commend, "translationX", -270F, 0F).setDuration(1000).start();//X轴平移旋转
            //设置收起评论选项的文字平移
            ObjectAnimator.ofFloat(commend_text, "translationX", -250F, 0F).setDuration(1000).start();//X轴平移旋转
            //赋值
            commend_text.setText("");
            //设置收起评论旋转动画
            ObjectAnimator.ofFloat(commend, "rotation", -1080F, 0F).setDuration(1000).start();//1080度旋转

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值