zoukankan      html  css  js  c++  java
  • ScrollView cannot scroll in Slidinguppanellayout 解决办法

    xml源码如下
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout 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:background="@color/white" >
    
        <com.sothree.slidinguppanel.SlidingUpPanelLayout
            xmlns:sothree="http://schemas.android.com/apk/res-auto"
            android:id="@+id/sliding_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="bottom"
            sothree:dragView="@+id/name"
            sothree:panelHeight="40dp"
            sothree:paralaxOffset="100dp"
            sothree:shadowHeight="4dp" >
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/white"
                android:orientation="vertical" >
    
                <RelativeLayout
                    android:id="@+id/rel_top_layout"
                    android:layout_width="fill_parent"
                    android:layout_height="50dp"
                    android:background="@color/t_blue" >
    
                    <TextView
                        android:id="@+id/title_text_tv"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_centerInParent="true"
                        android:text="统计图"
                        android:textColor="@color/white"
                        android:textSize="22sp" />
    
                    <Button
                        android:id="@+id/btn_back"
                        android:layout_width="50dp"
                        android:layout_height="fill_parent"
                        android:layout_alignParentLeft="true"
                        android:layout_centerVertical="true"
                        android:background="@drawable/back_btn_selector" />
                </RelativeLayout>
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_margin="10dp"
                    android:layout_weight="1"
                    android:background="@drawable/border" >
    
                    <LinearLayout
                        android:id="@+id/chart"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_margin="10dp"
                        android:orientation="vertical" >
                    </LinearLayout>
                </LinearLayout>
    
                <RadioGroup
                    android:id="@+id/radiogroup"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:orientation="horizontal" >
    
                    <RadioButton
                        android:id="@+id/radio_histogram"
                        style="@style/param_text_style"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:button="@drawable/radio_btn_selector"
                        android:onClick="changeGraph"
                        android:text="柱状图" />
    
                    <RadioButton
                        android:id="@+id/radio_line_graph"
                        style="@style/param_text_style"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:layout_margin="5dp"
                        android:layout_weight="1"
                        android:button="@drawable/radio_btn_selector"
                        android:onClick="changeGraph"
                        android:text="折线图" />
                </RadioGroup>
            </LinearLayout>
    
            <ScrollView
                android:id="@+id/scroll_view"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:clickable="true"
                    android:focusable="false"
                    android:orientation="vertical" >
    
                    <LinearLayout
                        android:id="@+id/drag"
                        android:layout_width="match_parent"
                        android:layout_height="40dp"
                        android:orientation="vertical" >
    
                        <ImageView
                            android:id="@+id/up"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="#1594df"
                            android:src="@drawable/icon_up"
                            android:visibility="visible" />
    
                        <ImageView
                            android:id="@+id/down"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:background="#1594df"
                            android:src="@drawable/icon_down"
                            android:visibility="gone" />
                    </LinearLayout>
    
                    <LinearLayout
                        android:id="@+id/table_view"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:layout_marginRight="10dp"
                        android:orientation="vertical" >
                    </LinearLayout>
                </LinearLayout>
            </ScrollView>
        </com.sothree.slidinguppanel.SlidingUpPanelLayout>
    
    </RelativeLayout>
    View Code

    在Activity中

            slidingUpPanel.setDragView(findViewById(R.id.drag));
        // can't add this line
    //        slidingUpPanel.setEnableDragViewTouchEvents(true);    

    在com.sothree.slidinguppanel.SlidingUpPanelLayout中的onInterceptTouchEvent 处理 case MotionEvent.ACTION_DOWN:

        private boolean isDragViewHit(int x, int y) {
            if (isExpanded()) {
                // don't intercept touch if panel expanded
                return false;
            } else {
                // original implementation - only allow dragging on mDragView
                View v = mDragView != null ? mDragView : mSlideableView;
                if (v == null)
                    return false;
                int[] viewLocation = new int[2];
                v.getLocationOnScreen(viewLocation);
                int[] parentLocation = new int[2];
                this.getLocationOnScreen(parentLocation);
                int screenX = parentLocation[0] + x;
                int screenY = parentLocation[1] + y;
                return screenX >= viewLocation[0] && screenX < viewLocation[0] + v.getWidth()
                        && screenY >= viewLocation[1] && screenY < viewLocation[1] + v.getHeight();
            }
        }
  • 相关阅读:
    Java函数调用
    Java编程工具的介绍
    Java关键字及作用
    Java面向对象
    Java代码内容概述
    Java构造方法
    Java面向对象
    Java数组概述和定义
    JDBC工具类,基于C3P0的数据库连接池,提供获取连接池、获取连接对象、释放资源和封装事务操作的方法
    图片爬虫工具,可以爬取指定网页的图片
  • 原文地址:https://www.cnblogs.com/zhuqiang/p/3709495.html
Copyright © 2011-2022 走看看