Scrollview中的嵌套Scrollview无效

问题描述 投票:-1回答:1

我想在Scrollview中有两个列表布局。我正在使用嵌套scrollview进行这两个列表布局。 Scrollview正在为第二个列表布局工作,但滚动视图不适用于第一个布局。父Scrollview也正在运行。第一个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>
android scrollview android-nestedscrollview
1个回答
1
投票

请试试这个。我希望你能有用。

请使用自定义ListView。

自定义ListView

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

<?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>
© www.soinside.com 2019 - 2024. All rights reserved.