NestedScrollView未显示所有内容

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

我正在尝试使用ScrollView作为我的mainActivity。在ScrollView内部使用水平LinearLayout。 LinearLayout的内容超出了屏幕尺寸。我希望能够在ScrollView中滚动它们,但是,ScrollView只显示筛选到屏幕的最后一个视图下方的几个像素。我需要它来显示和滚动所有内容。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:fillViewport="true"
android:isScrollContainer="false"
tools:context="Activities.MainActivity">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:weightSum="12">

    <android.support.constraint.ConstraintLayout
        android:id="@+id/relativeLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="3"
        android:background="@color/website_top_color">

        <Spinner
            android:id="@+id/countriesSpinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="20dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <Spinner
            android:id="@+id/currencySpinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="4dp"
            app:layout_constraintStart_toEndOf="@+id/countriesSpinner"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="16dp"
            android:layout_marginTop="4dp"
            android:drawablePadding="5dp"
            android:drawableStart="@drawable/ic_package"
            android:text="Premium Packages"
            android:textColor="@android:color/white"
            app:layout_constraintStart_toEndOf="@+id/currencySpinner"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/mainActivityLogin"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="16dp"
            android:layout_marginTop="4dp"
            android:text="Login"
            android:textColor="@android:color/white"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/view"
            app:layout_constraintTop_toBottomOf="@+id/textView" />

        <View
            android:id="@+id/view"
            android:layout_width="1.5dp"
            android:layout_height="0dp"
            android:layout_marginEnd="16dp"
            android:layout_marginTop="4dp"
            android:background="@android:color/white"
            app:layout_constraintBottom_toBottomOf="@+id/mainActivityRegistration"
            app:layout_constraintEnd_toStartOf="@+id/mainActivityRegistration"
            app:layout_constraintTop_toTopOf="@+id/mainActivityLogin"
            app:layout_constraintVertical_bias="1.0">

        </View>

        <TextView
            android:id="@+id/mainActivityRegistration"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="16dp"
            android:layout_marginTop="4dp"
            android:text="Register"
            android:textColor="@android:color/white"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView" />
    </android.support.constraint.ConstraintLayout>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="50dp"
        android:layout_marginTop="10dp"
        android:src="@mipmap/logo" />

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_margin="25dp"
        android:layout_weight="3"
        android:background="@android:color/darker_gray"
        app:cardBackgroundColor="@android:color/darker_gray"
        app:cardCornerRadius="5dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_margin="2.5dp"
            android:background="@android:color/white">

            <android.support.v7.widget.SearchView
                android:id="@+id/mainActivitySearch"
                android:layout_width="match_parent"
                android:layout_height="match_parent"></android.support.v7.widget.SearchView>
        </RelativeLayout>
    </android.support.v7.widget.CardView>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_marginEnd="100dp"
        android:layout_marginLeft="100dp"
        android:layout_marginRight="100dp"
        android:layout_marginStart="100dp"
        android:layout_marginTop="20dp"
        android:layout_weight="3"
        android:background="@android:color/darker_gray"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="1dp"
            android:background="@android:color/white"
            android:weightSum="6">

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2.98">

                <TextView
                    android:id="@+id/exchange"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:drawableStart="@drawable/ic_exchange"
                    android:text="( 0 )"
                    android:textColor="@color/website_top_color"
                    android:textSize="20sp" />
            </RelativeLayout>

            <View
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="@android:color/darker_gray" />

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="2">

                <ImageView
                    android:id="@+id/shopping_cart"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:src="@drawable/ic_shopping_cart" />
            </RelativeLayout>

            <View
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="@android:color/darker_gray" />

            <RelativeLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1">

                <ImageView
                    android:id="@+id/drawer"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerInParent="true"
                    android:src="@drawable/ic_list" />
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="LATEST FEATURED PRODUCTS"
        android:textColor="@android:color/black"
        android:textSize="24sp" />
    <android.support.v4.view.ViewPager
        android:id="@+id/banner"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_margin="25dp"
        android:layout_weight="12" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="BUNDLED PRODUCTS"
        android:textColor="@android:color/black"
        android:textSize="24sp" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="CLASSIFIED"
        android:textColor="@android:color/black"
        android:textSize="24sp" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/gridLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="9" />

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="27">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@mipmap/parralax_vendor"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:text="OUR VENDOR"
                android:textColor="@android:color/black"
                android:textSize="24sp" />

            <android.support.v4.view.ViewPager
                android:id="@+id/vendor"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="15dp" />
        </LinearLayout>
    </android.support.v7.widget.CardView>
</LinearLayout>

上面是我的xml。

android scrollview android-scrollview
1个回答
0
投票

我已经解决了这个问题。我发现在删除所有的weightSums和layout_weights之后,我的ScrollView工作得很好。

© www.soinside.com 2019 - 2024. All rights reserved.