【问题标题】:CardView is not scrollingCardView 不滚动
【发布时间】:2017-12-13 12:29:05
【问题描述】:

下面是我的代码,我在LinearLayout 中有多个cardview,但构建后我无法滚动它。一半的卡片视图被隐藏了。

有截图

我想滚动我所有的cardview。我尝试添加scrollview,但它不起作用。添加scrollview 后所有cardview 都不起作用

这是添加scrollview后发生的情况。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="eras.ppt.ras.MainActivity"
    android:orientation="vertical"
    android:padding="10dp"
    android:background="@drawable/backgroundimage"
    android:gravity="center"
    android:id="@+id/ll">

    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="20dp"
        android:background="@color/transblue"/>

    <LinearLayout
        android:id="@+id/SliderDots"
        android:layout_below="@+id/viewPager"
        android:orientation="horizontal"
        android:gravity="center_vertical|center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </LinearLayout>


    <LinearLayout
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/physics"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:gravity="center">
                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundpurple"
                    android:src="@drawable/sigma"
                    android:padding="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:layout_marginTop="10dp"
                    android:text="Physics"/>
                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/lightgray"
                    android:layout_margin="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Main Content"
                    android:padding="5dp"
                    android:textColor="@android:color/darker_gray"/>

            </LinearLayout>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/profile"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundgreen"
                    android:padding="10dp"
                    android:src="@drawable/profile" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="Profile"
                    android:textStyle="bold" />

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Access Profile"
                    android:textColor="@android:color/darker_gray" />

            </LinearLayout>
        </android.support.v7.widget.CardView>

    </LinearLayout>

    <LinearLayout
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/practice"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:gravity="center">
                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundyello"
                    android:src="@drawable/sigma"
                    android:padding="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:layout_marginTop="10dp"
                    android:text="Practice"/>
                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/lightgray"
                    android:layout_margin="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Examination"
                    android:padding="5dp"
                    android:textColor="@android:color/darker_gray"/>

            </LinearLayout>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/study_material"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundpink"
                    android:padding="10dp"
                    android:src="@drawable/profile" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="Study Material"
                    android:textStyle="bold" />

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Access Study related stuff"
                    android:textColor="@android:color/darker_gray" />

            </LinearLayout>
        </android.support.v7.widget.CardView>

    </LinearLayout>

    <LinearLayout
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/setting"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:gravity="center">
                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundpurple"
                    android:src="@drawable/sigma"
                    android:padding="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:layout_marginTop="10dp"
                    android:text="Setting"/>
                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/lightgray"
                    android:layout_margin="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Change Setting of App"
                    android:padding="5dp"
                    android:textColor="@android:color/darker_gray"/>

            </LinearLayout>
        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/bout"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundtransblue"
                    android:padding="10dp"
                    android:src="@mipmap/ic_launcher" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="About Us"
                    android:textStyle="bold" />

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="PPT"
                    android:textColor="@android:color/darker_gray" />

            </LinearLayout>
        </android.support.v7.widget.CardView>

    </LinearLayout>

    <LinearLayout
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/chat"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:gravity="center">
                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundtransblue"
                    android:src="@drawable/quote"
                    android:padding="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:layout_marginTop="10dp"
                    android:text="Q/A"/>
                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/lightgray"
                    android:layout_margin="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Discussion"
                    android:padding="5dp"
                    android:textColor="@android:color/darker_gray"/>

            </LinearLayout>
        </android.support.v7.widget.CardView>
    </LinearLayout>

</LinearLayout>

【问题讨论】:

  • 你能用你的滚动视图显示代码吗?你把它放在哪里了?你试过用滚动视图封闭cardview的线性布局吗?

标签: android android-layout android-scrollview cardview


【解决方案1】:

使用NestedScrollView 如下代码

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="eras.ppt.ras.MainActivity"
    android:orientation="vertical"
    android:padding="10dp"
    android:background="@drawable/backgroundimage"
    android:gravity="center"
    android:id="@+id/ll">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

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


    <android.support.v4.view.ViewPager
        android:id="@+id/viewPager"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="20dp"
        android:background="@color/transblue"/>

    <LinearLayout
        android:id="@+id/SliderDots"
        android:layout_below="@+id/viewPager"
        android:orientation="horizontal"
        android:gravity="center_vertical|center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    </LinearLayout>


    <LinearLayout
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/physics"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:gravity="center">
                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundpurple"
                    android:src="@drawable/sigma"
                    android:padding="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:layout_marginTop="10dp"
                    android:text="Physics"/>
                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/lightgray"
                    android:layout_margin="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Main Content"
                    android:padding="5dp"
                    android:textColor="@android:color/darker_gray"/>

            </LinearLayout>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/profile"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundgreen"
                    android:padding="10dp"
                    android:src="@drawable/profile" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="Profile"
                    android:textStyle="bold" />

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Access Profile"
                    android:textColor="@android:color/darker_gray" />

            </LinearLayout>
        </android.support.v7.widget.CardView>

    </LinearLayout>

    <LinearLayout
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/practice"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:gravity="center">
                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundyello"
                    android:src="@drawable/sigma"
                    android:padding="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:layout_marginTop="10dp"
                    android:text="Practice"/>
                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/lightgray"
                    android:layout_margin="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Examination"
                    android:padding="5dp"
                    android:textColor="@android:color/darker_gray"/>

            </LinearLayout>
        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/study_material"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundpink"
                    android:padding="10dp"
                    android:src="@drawable/profile" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="Study Material"
                    android:textStyle="bold" />

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="Access Study related stuff"
                    android:textColor="@android:color/darker_gray" />

            </LinearLayout>
        </android.support.v7.widget.CardView>

    </LinearLayout>

    <LinearLayout
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/setting"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:gravity="center">
                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundpurple"
                    android:src="@drawable/sigma"
                    android:padding="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:layout_marginTop="10dp"
                    android:text="Setting"/>
                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/lightgray"
                    android:layout_margin="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Change Setting of App"
                    android:padding="5dp"
                    android:textColor="@android:color/darker_gray"/>

            </LinearLayout>
        </android.support.v7.widget.CardView>

        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/bout"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundtransblue"
                    android:padding="10dp"
                    android:src="@mipmap/ic_launcher" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="About Us"
                    android:textStyle="bold" />

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

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:padding="5dp"
                    android:text="PPT"
                    android:textColor="@android:color/darker_gray" />

            </LinearLayout>
        </android.support.v7.widget.CardView>

    </LinearLayout>

    <LinearLayout
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.CardView
            android:foreground="?android:attr/selectableItemBackground"
            android:clickable="true"
            android:id="@+id/chat"
            android:layout_width="160dp"
            android:layout_height="190dp"
            android:layout_margin="10dp">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:gravity="center">
                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/cerclebackgroundtransblue"
                    android:src="@drawable/quote"
                    android:padding="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textStyle="bold"
                    android:layout_marginTop="10dp"
                    android:text="Q/A"/>
                <View
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="@color/lightgray"
                    android:layout_margin="10dp"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Discussion"
                    android:padding="5dp"
                    android:textColor="@android:color/darker_gray"/>

            </LinearLayout>
        </android.support.v7.widget.CardView>
    </LinearLayout>
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

【讨论】:

    【解决方案2】:

    只需将ScrollView 放在&lt;?xml version="1.0" encoding="utf-8"?&gt; 之后

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    

    并在文件末尾关闭它。 &lt;/ScrollView&gt;

    并从第一个 LinearLayout 中删除此行

    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"
    

    【讨论】:

      【解决方案3】:

      您需要将ScrollView 作为您的父布局来滚动您的控件

       <ScrollView
           android:layout_width="match_parent"
           android:fillViewport="true"
           android:layout_height="match_parent">
      
           <LinearLayout
               android:layout_width="match_parent"
               android:orientation="vertical"
               android:layout_height="match_parent">
      
                  <!--add here all your controll-->
           </LinearLayout>
       </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:layout_width="match_parent"
          android:layout_height="match_parent"
          android:fillViewport="true">
      
          <LinearLayout 
              android:id="@+id/ll"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:background="@drawable/backgroundimage"
              android:gravity="center"
              android:orientation="vertical"
              android:padding="10dp"
              tools:context="eras.ppt.ras.MainActivity">
      
              <android.support.v4.view.ViewPager
                  android:id="@+id/viewPager"
                  android:layout_width="match_parent"
                  android:layout_height="200dp"
                  android:layout_marginBottom="20dp"
                  android:layout_marginTop="10dp"
                  android:background="@color/transblue" />
      
              <LinearLayout
                  android:id="@+id/SliderDots"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:layout_below="@+id/viewPager"
                  android:gravity="center_vertical|center_horizontal"
                  android:orientation="horizontal">
      
              </LinearLayout>
      
      
              <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:clipToPadding="false"
                  android:gravity="center"
                  android:orientation="horizontal">
      
                  <android.support.v7.widget.CardView
                      android:id="@+id/physics"
                      android:layout_width="160dp"
                      android:layout_height="190dp"
                      android:layout_margin="10dp"
                      android:clickable="true"
                      android:foreground="?android:attr/selectableItemBackground">
      
                      <LinearLayout
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:gravity="center"
                          android:orientation="vertical">
      
                          <ImageView
                              android:layout_width="64dp"
                              android:layout_height="64dp"
                              android:background="@drawable/cerclebackgroundpurple"
                              android:padding="10dp"
                              android:src="@drawable/sigma" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_marginTop="10dp"
                              android:text="Physics"
                              android:textStyle="bold" />
      
                          <View
                              android:layout_width="match_parent"
                              android:layout_height="1dp"
                              android:layout_margin="10dp"
                              android:background="@color/lightgray" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:gravity="center"
                              android:padding="5dp"
                              android:text="Main Content"
                              android:textColor="@android:color/darker_gray" />
      
                      </LinearLayout>
                  </android.support.v7.widget.CardView>
      
                  <android.support.v7.widget.CardView
                      android:id="@+id/profile"
                      android:layout_width="160dp"
                      android:layout_height="190dp"
                      android:layout_margin="10dp"
                      android:clickable="true"
                      android:foreground="?android:attr/selectableItemBackground">
      
                      <LinearLayout
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:gravity="center"
                          android:orientation="vertical">
      
                          <ImageView
                              android:layout_width="64dp"
                              android:layout_height="64dp"
                              android:background="@drawable/cerclebackgroundgreen"
                              android:padding="10dp"
                              android:src="@drawable/profile" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_marginTop="10dp"
                              android:text="Profile"
                              android:textStyle="bold" />
      
                          <View
                              android:layout_width="match_parent"
                              android:layout_height="1dp"
                              android:layout_margin="10dp"
                              android:background="@color/lightgray" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:gravity="center"
                              android:padding="5dp"
                              android:text="Access Profile"
                              android:textColor="@android:color/darker_gray" />
      
                      </LinearLayout>
                  </android.support.v7.widget.CardView>
      
              </LinearLayout>
      
              <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:clipToPadding="false"
                  android:gravity="center"
                  android:orientation="horizontal">
      
                  <android.support.v7.widget.CardView
                      android:id="@+id/practice"
                      android:layout_width="160dp"
                      android:layout_height="190dp"
                      android:layout_margin="10dp"
                      android:clickable="true"
                      android:foreground="?android:attr/selectableItemBackground">
      
                      <LinearLayout
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:gravity="center"
                          android:orientation="vertical">
      
                          <ImageView
                              android:layout_width="64dp"
                              android:layout_height="64dp"
                              android:background="@drawable/cerclebackgroundyello"
                              android:padding="10dp"
                              android:src="@drawable/sigma" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_marginTop="10dp"
                              android:text="Practice"
                              android:textStyle="bold" />
      
                          <View
                              android:layout_width="match_parent"
                              android:layout_height="1dp"
                              android:layout_margin="10dp"
                              android:background="@color/lightgray" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:gravity="center"
                              android:padding="5dp"
                              android:text="Examination"
                              android:textColor="@android:color/darker_gray" />
      
                      </LinearLayout>
                  </android.support.v7.widget.CardView>
      
                  <android.support.v7.widget.CardView
                      android:id="@+id/study_material"
                      android:layout_width="160dp"
                      android:layout_height="190dp"
                      android:layout_margin="10dp"
                      android:clickable="true"
                      android:foreground="?android:attr/selectableItemBackground">
      
                      <LinearLayout
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:gravity="center"
                          android:orientation="vertical">
      
                          <ImageView
                              android:layout_width="64dp"
                              android:layout_height="64dp"
                              android:background="@drawable/cerclebackgroundpink"
                              android:padding="10dp"
                              android:src="@drawable/profile" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_marginTop="10dp"
                              android:text="Study Material"
                              android:textStyle="bold" />
      
                          <View
                              android:layout_width="match_parent"
                              android:layout_height="1dp"
                              android:layout_margin="10dp"
                              android:background="@color/lightgray" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:gravity="center"
                              android:padding="5dp"
                              android:text="Access Study related stuff"
                              android:textColor="@android:color/darker_gray" />
      
                      </LinearLayout>
                  </android.support.v7.widget.CardView>
      
              </LinearLayout>
      
              <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:clipToPadding="false"
                  android:gravity="center"
                  android:orientation="horizontal">
      
                  <android.support.v7.widget.CardView
                      android:id="@+id/setting"
                      android:layout_width="160dp"
                      android:layout_height="190dp"
                      android:layout_margin="10dp"
                      android:clickable="true"
                      android:foreground="?android:attr/selectableItemBackground">
      
                      <LinearLayout
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:gravity="center"
                          android:orientation="vertical">
      
                          <ImageView
                              android:layout_width="64dp"
                              android:layout_height="64dp"
                              android:background="@drawable/cerclebackgroundpurple"
                              android:padding="10dp"
                              android:src="@drawable/sigma" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_marginTop="10dp"
                              android:text="Setting"
                              android:textStyle="bold" />
      
                          <View
                              android:layout_width="match_parent"
                              android:layout_height="1dp"
                              android:layout_margin="10dp"
                              android:background="@color/lightgray" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:gravity="center"
                              android:padding="5dp"
                              android:text="Change Setting of App"
                              android:textColor="@android:color/darker_gray" />
      
                      </LinearLayout>
                  </android.support.v7.widget.CardView>
      
                  <android.support.v7.widget.CardView
                      android:id="@+id/bout"
                      android:layout_width="160dp"
                      android:layout_height="190dp"
                      android:layout_margin="10dp"
                      android:clickable="true"
                      android:foreground="?android:attr/selectableItemBackground">
      
                      <LinearLayout
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:gravity="center"
                          android:orientation="vertical">
      
                          <ImageView
                              android:layout_width="64dp"
                              android:layout_height="64dp"
                              android:background="@drawable/cerclebackgroundtransblue"
                              android:padding="10dp"
                              android:src="@mipmap/ic_launcher" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_marginTop="10dp"
                              android:text="About Us"
                              android:textStyle="bold" />
      
                          <View
                              android:layout_width="match_parent"
                              android:layout_height="1dp"
                              android:layout_margin="10dp"
                              android:background="@color/lightgray" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:gravity="center"
                              android:padding="5dp"
                              android:text="PPT"
                              android:textColor="@android:color/darker_gray" />
      
                      </LinearLayout>
                  </android.support.v7.widget.CardView>
      
              </LinearLayout>
      
              <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:clipToPadding="false"
                  android:gravity="center"
                  android:orientation="horizontal">
      
                  <android.support.v7.widget.CardView
                      android:id="@+id/chat"
                      android:layout_width="160dp"
                      android:layout_height="190dp"
                      android:layout_margin="10dp"
                      android:clickable="true"
                      android:foreground="?android:attr/selectableItemBackground">
      
                      <LinearLayout
                          android:layout_width="match_parent"
                          android:layout_height="match_parent"
                          android:gravity="center"
                          android:orientation="vertical">
      
                          <ImageView
                              android:layout_width="64dp"
                              android:layout_height="64dp"
                              android:background="@drawable/cerclebackgroundtransblue"
                              android:padding="10dp"
                              android:src="@drawable/quote" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:layout_marginTop="10dp"
                              android:text="Q/A"
                              android:textStyle="bold" />
      
                          <View
                              android:layout_width="match_parent"
                              android:layout_height="1dp"
                              android:layout_margin="10dp"
                              android:background="@color/lightgray" />
      
                          <TextView
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:gravity="center"
                              android:padding="5dp"
                              android:text="Discussion"
                              android:textColor="@android:color/darker_gray" />
      
                      </LinearLayout>
                  </android.support.v7.widget.CardView>
              </LinearLayout>
      
          </LinearLayout>
      </ScrollView>
      

      【讨论】:

        【解决方案4】:

        如果你想让你的 ViewPager 是静态的并且只有 CardView 的下面部分是 Scroll 那么下面是解决它的完美方法。

        <LinearLayout
            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:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:padding="10dp"
            android:background="#252562"
            android:gravity="center"
            android:id="@+id/ll">
        
            <android.support.v4.view.ViewPager
                android:id="@+id/viewPager"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:layout_marginTop="10dp"
                android:layout_marginBottom="20dp"
                android:background="#969696"/>
        
            <LinearLayout
                android:id="@+id/SliderDots"
                android:layout_below="@+id/viewPager"
                android:orientation="horizontal"
                android:gravity="center_vertical|center_horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
        
            </LinearLayout>
        
            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">
        
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical">
        
                    <LinearLayout
                        android:clipToPadding="false"
                        android:gravity="center"
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <android.support.v7.widget.CardView
                            android:foreground="?android:attr/selectableItemBackground"
                            android:clickable="true"
                            android:id="@+id/physics"
                            android:layout_width="160dp"
                            android:layout_height="190dp"
                            android:layout_margin="10dp">
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:orientation="vertical"
                                android:gravity="center">
                                <ImageView
                                    android:layout_width="64dp"
                                    android:layout_height="64dp"
                                    android:background="#ff0000"
                                    android:src="@drawable/ic_account"
                                    android:padding="10dp"/>
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:textStyle="bold"
                                    android:layout_marginTop="10dp"
                                    android:text="Physics"/>
                                <View
                                    android:layout_width="match_parent"
                                    android:layout_height="1dp"
                                    android:background="@color/primary"
                                    android:layout_margin="10dp"/>
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:gravity="center"
                                    android:text="Main Content"
                                    android:padding="5dp"
                                    android:textColor="@android:color/darker_gray"/>
        
                            </LinearLayout>
                        </android.support.v7.widget.CardView>
                        <android.support.v7.widget.CardView
                            android:foreground="?android:attr/selectableItemBackground"
                            android:clickable="true"
                            android:id="@+id/profile"
                            android:layout_width="160dp"
                            android:layout_height="190dp"
                            android:layout_margin="10dp">
        
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:gravity="center"
                                android:orientation="vertical">
        
                                <ImageView
                                    android:layout_width="64dp"
                                    android:layout_height="64dp"
                                    android:background="#00ff00"
                                    android:padding="10dp"
                                    android:src="@drawable/ic_phone" />
        
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_marginTop="10dp"
                                    android:text="Profile"
                                    android:textStyle="bold" />
        
                                <View
                                    android:layout_width="match_parent"
                                    android:layout_height="1dp"
                                    android:layout_margin="10dp"
                                    android:background="@color/cardview_shadow_end_color" />
        
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:gravity="center"
                                    android:padding="5dp"
                                    android:text="Access Profile"
                                    android:textColor="@android:color/darker_gray" />
        
                            </LinearLayout>
                        </android.support.v7.widget.CardView>
        
                    </LinearLayout>
        
                    <LinearLayout
                        android:clipToPadding="false"
                        android:gravity="center"
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <android.support.v7.widget.CardView
                            android:foreground="?android:attr/selectableItemBackground"
                            android:clickable="true"
                            android:id="@+id/practice"
                            android:layout_width="160dp"
                            android:layout_height="190dp"
                            android:layout_margin="10dp">
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:orientation="vertical"
                                android:gravity="center">
                                <ImageView
                                    android:layout_width="64dp"
                                    android:layout_height="64dp"
                                    android:background="#ff0000"
                                    android:src="@drawable/quila"
                                    android:padding="10dp"/>
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:textStyle="bold"
                                    android:layout_marginTop="10dp"
                                    android:text="Practice"/>
                                <View
                                    android:layout_width="match_parent"
                                    android:layout_height="1dp"
                                    android:background="@color/primary"
                                    android:layout_margin="10dp"/>
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:gravity="center"
                                    android:text="Examination"
                                    android:padding="5dp"
                                    android:textColor="@android:color/darker_gray"/>
        
                            </LinearLayout>
                        </android.support.v7.widget.CardView>
                        <android.support.v7.widget.CardView
                            android:foreground="?android:attr/selectableItemBackground"
                            android:clickable="true"
                            android:id="@+id/study_material"
                            android:layout_width="160dp"
                            android:layout_height="190dp"
                            android:layout_margin="10dp">
        
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:gravity="center"
                                android:orientation="vertical">
        
                                <ImageView
                                    android:layout_width="64dp"
                                    android:layout_height="64dp"
                                    android:background="#00ff00"
                                    android:padding="10dp"
                                    android:src="@drawable/quila2" />
        
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_marginTop="10dp"
                                    android:text="Study Material"
                                    android:textStyle="bold" />
        
                                <View
                                    android:layout_width="match_parent"
                                    android:layout_height="1dp"
                                    android:layout_margin="10dp"
                                    android:background="@color/cardview_dark_background" />
        
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:gravity="center"
                                    android:padding="5dp"
                                    android:text="Access Study related stuff"
                                    android:textColor="@android:color/darker_gray" />
        
                            </LinearLayout>
                        </android.support.v7.widget.CardView>
        
                    </LinearLayout>
        
                    <LinearLayout
                        android:clipToPadding="false"
                        android:gravity="center"
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <android.support.v7.widget.CardView
                            android:foreground="?android:attr/selectableItemBackground"
                            android:clickable="true"
                            android:id="@+id/setting"
                            android:layout_width="160dp"
                            android:layout_height="190dp"
                            android:layout_margin="10dp">
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:orientation="vertical"
                                android:gravity="center">
                                <ImageView
                                    android:layout_width="64dp"
                                    android:layout_height="64dp"
                                    android:background="#ff0000"
                                    android:src="@drawable/sea"
        
                                    android:padding="10dp"/>
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:textStyle="bold"
                                    android:layout_marginTop="10dp"
                                    android:text="Setting"/>
                                <View
                                    android:layout_width="match_parent"
                                    android:layout_height="1dp"
                                    android:background="@color/cardview_shadow_start_color"
                                    android:layout_margin="10dp"/>
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:gravity="center"
                                    android:text="Change Setting of App"
                                    android:padding="5dp"
                                    android:textColor="@android:color/darker_gray"/>
        
                            </LinearLayout>
                        </android.support.v7.widget.CardView>
        
                        <android.support.v7.widget.CardView
                            android:foreground="?android:attr/selectableItemBackground"
                            android:clickable="true"
                            android:id="@+id/bout"
                            android:layout_width="160dp"
                            android:layout_height="190dp"
                            android:layout_margin="10dp">
        
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:gravity="center"
                                android:orientation="vertical">
        
                                <ImageView
                                    android:layout_width="64dp"
                                    android:layout_height="64dp"
                                    android:background="#265614"
                                    android:padding="10dp"
                                    android:src="@mipmap/ic_launcher" />
        
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:layout_marginTop="10dp"
                                    android:text="About Us"
                                    android:textStyle="bold" />
        
                                <View
                                    android:layout_width="match_parent"
                                    android:layout_height="1dp"
                                    android:layout_margin="10dp"
                                    android:background="#546633" />
        
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:gravity="center"
                                    android:padding="5dp"
                                    android:text="PPT"
                                    android:textColor="@android:color/darker_gray" />
        
                            </LinearLayout>
                        </android.support.v7.widget.CardView>
        
                    </LinearLayout>
        
                    <LinearLayout
                        android:clipToPadding="false"
                        android:gravity="center"
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <android.support.v7.widget.CardView
                            android:foreground="?android:attr/selectableItemBackground"
                            android:clickable="true"
                            android:id="@+id/chat"
                            android:layout_width="160dp"
                            android:layout_height="190dp"
                            android:layout_margin="10dp">
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:orientation="vertical"
                                android:gravity="center">
                                <ImageView
                                    android:layout_width="64dp"
                                    android:layout_height="64dp"
                                    android:background="#969696"
                                    android:src="@mipmap/ic_launcher"
                                    android:padding="10dp"/>
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:textStyle="bold"
                                    android:layout_marginTop="10dp"
                                    android:text="Q/A"/>
                                <View
                                    android:layout_width="match_parent"
                                    android:layout_height="1dp"
                                    android:background="@color/primary"
                                    android:layout_margin="10dp"/>
                                <TextView
                                    android:layout_width="wrap_content"
                                    android:layout_height="wrap_content"
                                    android:gravity="center"
                                    android:text="Discussion"
                                    android:padding="5dp"
                                    android:textColor="@android:color/darker_gray"/>
        
                            </LinearLayout>
                        </android.support.v7.widget.CardView>
                    </LinearLayout>
        
                </LinearLayout>
        
            </ScrollView>
        
        </LinearLayout>
        

        如果您想同时滚动两者,则将 ScrollView 作为主布局并删除内部滚动视图。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2018-11-28
          • 1970-01-01
          • 2021-04-03
          • 2020-08-22
          • 1970-01-01
          • 1970-01-01
          • 2020-07-05
          • 2016-11-06
          相关资源
          最近更新 更多