Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/221.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Scrollview中的嵌套Scrollview不工作_Android_Scrollview_Android Nestedscrollview - Fatal编程技术网

Android Scrollview中的嵌套Scrollview不工作

Android Scrollview中的嵌套Scrollview不工作,android,scrollview,android-nestedscrollview,Android,Scrollview,Android Nestedscrollview,我试图在一个滚动视图中有两个列表布局。我使用嵌套的scrollview作为两个列表布局。Scrollview适用于第二个列表布局,但scroll view不适用于第一个布局。父Scrollview也在工作。第一个listview的问题。第一个listview的Scrollview不工作。我哪里做错了 <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.a

我试图在一个滚动视图中有两个列表布局。我使用嵌套的scrollview作为两个列表布局。Scrollview适用于第二个列表布局,但scroll view不适用于第一个布局。父Scrollview也在工作。第一个listview的问题。第一个listview的Scrollview不工作。我哪里做错了

    <?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:gravity="center"
        android:orientation="vertical">

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_margin="20dp"
            android:background="@android:color/white"
            android:padding="10dp">

            <LinearLayout

                android:id="@+id/slistLayout1"
                android:layout_weight="4"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:orientation="horizontal"
                >



                <ListView
                    android:id="@+id/pListView1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="4"
                    android:descendantFocusability="blocksDescendants"
                    android:fadeScrollbars="false"
                    android:scrollbarAlwaysDrawVerticalTrack="true"
                    android:scrollbarStyle="insideInset"
                    android:clickable="true"
                    android:focusable="true" >
                </ListView>

            </LinearLayout>

        </android.support.v4.widget.NestedScrollView>


        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:layout_margin="20dp"
            android:background="@android:color/white"
            android:padding="10dp">

            <LinearLayout

                android:id="@+id/slistLayout2"
                android:layout_weight="4"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:orientation="horizontal"
                >



                <ListView
                    android:id="@+id/pListView2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="4"
                    android:descendantFocusability="blocksDescendants"
                    android:fadeScrollbars="false"

                    android:scrollbarAlwaysDrawVerticalTrack="true"
                    android:scrollbarStyle="insideInset"
                    android:clickable="true"
                    android:focusable="true" >
                </ListView>

            </LinearLayout>

        </android.support.v4.widget.NestedScrollView>




        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:src="@drawable/back"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"

            android:src="@drawable/footer"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"

            android:src="@drawable/cross"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:src="@drawable/dcr_online"/>





        <Button
            android:id="@+id/backbt"
            android:layout_width="50sp"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:background="@drawable/add_button_selector"
            android:layout_marginBottom="5dp"
            android:gravity="center"
            android:hapticFeedbackEnabled="true"
            android:onClick="finishActivity"
            android:soundEffectsEnabled="true"
            android:text="&lt;"
            android:textColor="#FFF"
            android:textSize="25sp"
            />




    </LinearLayout>



</ScrollView>

请试试这个。我希望你能帮上忙

请使用自定义列表视图

自定义列表视图

XML


change
android.support.v4.widget.NestedScrollView
from
ScrollView
public class MyCustomListView extends ListView {

    public MyCustomListView(Context context) {
        super(context);
    }

    public MyCustomListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyCustomListView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

        int heightSpec;

        if (getLayoutParams().height == LayoutParams.FILL_PARENT) {
            heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        } else {
            heightSpec = heightMeasureSpec;
        }

        super.onMeasure(widthMeasureSpec, heightSpec);
    }
}
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout

        android:id="@+id/slistLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">

        <your_packagename.MyCustomListView
            android:id="@+id/pListView1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="4"
            android:clickable="true"
            android:descendantFocusability="blocksDescendants"
            android:fadeScrollbars="false"
            android:focusable="true"
            android:scrollbarAlwaysDrawVerticalTrack="true"
            android:scrollbarStyle="insideInset" />


        <your_packagename.MyCustomListView
            android:id="@+id/pListView2"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="4"
            android:clickable="true"
            android:descendantFocusability="blocksDescendants"
            android:fadeScrollbars="false"
            android:focusable="true"
            android:scrollbarAlwaysDrawVerticalTrack="true"
            android:scrollbarStyle="insideInset" />


        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:src="@drawable/back"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"

            android:src="@drawable/footer"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"

            android:src="@drawable/cross"/>

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="20dp"
            android:src="@drawable/dcr_online"/>





        <Button
            android:id="@+id/backbt"
            android:layout_width="50sp"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:background="@drawable/add_button_selector"
            android:layout_marginBottom="5dp"
            android:gravity="center"
            android:hapticFeedbackEnabled="true"
            android:onClick="finishActivity"
            android:soundEffectsEnabled="true"
            android:text="&lt;"
            android:textColor="#FFF"
            android:textSize="25sp"
            />


    </LinearLayout>


</ScrollView>