关闭

左划商品详情UI处理

标签: 左划商品详情 仿淘宝
2025人阅读 评论(0) 收藏 举报
分类:

工作需要,做一个左划的事件,类似淘宝的商品详情的轮播图,最后一个左划到详情,第一个想法,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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:30330次
    • 积分:574
    • 等级:
    • 排名:千里之外
    • 原创:28篇
    • 转载:1篇
    • 译文:0篇
    • 评论:10条
    博客专栏
    最新评论