左划商品详情UI处理

工作需要,做一个左划的事件,类似淘宝的商品详情的轮播图,最后一个左划到详情,第一个想法,RefreshLayout横过来就好了,但是时间不允许,后来就一直耽搁了,最后使用的一个简单的办法:很low

使用 HorizontalScrolView 通过滑动监听做到

直接贴下代码吧,没啥难度;

<HorizontalScrollView
    android:id="@+id/horizontalScrollView"
    android:layout_width="match_parent"
    android:layout_height="@dimen/dp_341"
    android:scrollbars="none">


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

            <ImageView
                android:id="@+id/iv_goodsDetail_pic"
                android:layout_width="match_parent"
                android:layout_height="@dimen/dp_341"
                android:scaleType="centerCrop"
                android:src="@mipmap/goodsimg" />
        <LinearLayout
            android:layout_toRightOf="@+id/iv_goodsDetail_pic"
            android:id="@+id/ll_zuohua"
            android:layout_width="90dp"
            android:layout_height="match_parent"
            android:background="#eeeeee"
            android:orientation="horizontal">

            <ImageView
                android:id="@+id/iv_zuohua"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="@dimen/dp_5"
                android:src="@mipmap/zuohua" />

            <TextView
                android:id="@+id/tv_zuohua"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:layout_marginLeft="@dimen/dp_5"
                android:text="@string/zuohua"
                android:textColor="#808080"
                android:textSize="12sp" />
        </LinearLayout>
      
</HorizontalScrollView>










horizontalScrollView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {

            case MotionEvent.ACTION_DOWN:
                LogUtils.i("onTouch:  " + "ACTION_DOWN");
                break;
            case MotionEvent.ACTION_MOVE:
                int zuohua1 = ll_zuohua.getMeasuredWidth() / 2;
                LogUtils.i("onTouch:  " + "ACTION_MOVE" + "\nv.getScrollX()" + v.getScrollX());
                if (v.getScrollX() >= zuohua1 && rotateState.equals("zuohua")) {
                    RotateAnimation rotateAnimation1 = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                    rotateAnimation1.setDuration(500);
                    rotateAnimation1.setFillAfter(true);
                    iv_zuohua.startAnimation(rotateAnimation1);
                    tv_zuohua.setText(R.string.shifang);
                    rotateState = "shifang";
                } else if (v.getScrollX() < zuohua1 && rotateState.equals("shifang")) {
                    RotateAnimation rotateAnimation1 = new RotateAnimation(180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
                    rotateAnimation1.setDuration(500);
                    rotateAnimation1.setFillAfter(true);
                    iv_zuohua.startAnimation(rotateAnimation1);
                    tv_zuohua.setText(R.string.zuohua);
                    rotateState = "zuohua";
                }
                break;
            case MotionEvent.ACTION_UP:
                int zuohua = ll_zuohua.getMeasuredWidth() / 2;
                if (v.getScrollX() > zuohua) {
                    LogUtils.i("onTouch:  " + "ACTION_UP1" + "\nv.getScrollX()" + v.getScrollX() + "\nzuohuaWidth/2" + zuohua);
                    v.scrollBy(ll_zuohua.getMeasuredWidth(), 0);
                    if (drawUrl == null) {

                    } else {
                        intent.putExtra("key", "goods_detail");
                        intent.putExtra("goodsname", goodsName);
                        intent.putExtra("drawUrl", drawUrl);
                        startActivity(intent);
                        v.scrollTo(0, 0);
                        rotateState = "zuohua";
                    }
                } else {
                    LogUtils.i("onTouch:  " + "ACTION_UP2" + "\nv.getScrollX()" + v.getScrollX() + "\nzuohuaWidth/2=" + v.getScrollY());
                    v.scrollTo(0, 0);
                }
                iv_zuohua.clearAnimation();
                tv_zuohua.setText(R.string.zuohua);
                break;

        }
        return false;
    }
});



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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值