簡體   English   中英

如何使cardview成為具有可滾動內容的父布局

[英]how to make cardview a parent layout with scrollable content

我正在某個應用程序上工作,但想使Card View小部件成為父級布局,問題是我的內容在Cardview小部件內無法垂直滾動,謝謝。 這是我的代碼;

tools:context="com.example.hacker.guidekyu.Home">

<!-- TODO: Update blank fragment layout -->
<LinearLayout
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="wrap_content">

    <TextView
        android:layout_gravity="center"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25dp"
        android:text="   WELCOME TO KYU"
        />
    <ViewFlipper
        android:id="@+id/bckgrndViewFlipper1"
        android:layout_width="fill_parent"
        android:layout_height="200dp">

        <ImageView
            android:id="@+id/bckgrndImageView8"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="centerCrop"
            android:src="@mipmap/one" />

        <ImageView
            android:id="@+id/bckgrndImageView7"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="centerCrop"
            android:src="@mipmap/two" />

        <ImageView
            android:id="@+id/bckgrndImageView6"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="centerCrop"
            android:src="@mipmap/three" />

        <ImageView
            android:id="@+id/bckgrndImageView5"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="centerCrop"
            android:src="@mipmap/two" />

        <ImageView
            android:id="@+id/bckgrndImageView4"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scaleType="centerCrop"
            android:src="@mipmap/one" />


    </ViewFlipper>


    <android.support.v7.widget.CardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff0"
        android:layout_margin="8dp">
        <LinearLayout
            android:layout_width="fill_parent"
            android:orientation="horizontal"
            android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="fill_parent"

            android:background="#58a3c1"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="fill_parent"
                android:orientation="vertical"
                android:layout_weight="50"
                android:layout_marginLeft="20dp"
                android:gravity="center"
                android:layout_height="wrap_content">
                <ImageButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/ic_launcher"
                    />
                <TextView
                    android:gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Administration"
                    />
            </LinearLayout>
            <LinearLayout
                android:layout_weight="50"
                android:layout_width="fill_parent"
                android:orientation="vertical"
                android:layout_marginLeft="20dp"
                android:gravity="center"
                android:layout_height="wrap_content">
                <ImageButton
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:src="@mipmap/ic_launcher"
                    />
                <TextView
                    android:gravity="center"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Administration"
                    />
            </LinearLayout>
        </LinearLayout>
        </LinearLayout>

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

    <android.support.v7.widget.CardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff0"
        android:layout_margin="8dp">
        <LinearLayout
            android:layout_width="fill_parent"
            android:orientation="horizontal"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="fill_parent"

                android:background="#58a3c1"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:orientation="vertical"
                    android:layout_weight="50"
                    android:layout_marginLeft="20dp"
                    android:gravity="center"
                    android:layout_height="wrap_content">
                    <ImageButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher"
                        />
                    <TextView
                        android:gravity="center"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Administration"
                        />
                </LinearLayout>
                <LinearLayout
                    android:layout_weight="50"
                    android:layout_width="fill_parent"
                    android:orientation="vertical"
                    android:layout_marginLeft="20dp"
                    android:gravity="center"
                    android:layout_height="wrap_content">
                    <ImageButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher"
                        />
                    <TextView
                        android:gravity="center"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Administration"
                        />
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

    </android.support.v7.widget.CardView>
    <android.support.v7.widget.CardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff0"
        android:layout_margin="8dp">
        <LinearLayout
            android:layout_width="fill_parent"
            android:orientation="horizontal"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="fill_parent"

                android:background="#58a3c1"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:orientation="vertical"
                    android:layout_weight="50"
                    android:layout_marginLeft="20dp"
                    android:gravity="center"
                    android:layout_height="wrap_content">
                    <ImageButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher"
                        />
                    <TextView
                        android:gravity="center"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Administration"
                        />
                </LinearLayout>
                <LinearLayout
                    android:layout_weight="50"
                    android:layout_width="fill_parent"
                    android:orientation="vertical"
                    android:layout_marginLeft="20dp"
                    android:gravity="center"
                    android:layout_height="wrap_content">
                    <ImageButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher"
                        />
                    <TextView
                        android:gravity="center"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Administration"
                        />
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

    </android.support.v7.widget.CardView>
    <android.support.v7.widget.CardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ff"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff0"
        android:layout_margin="8dp">
        <LinearLayout
            android:layout_width="fill_parent"
            android:orientation="horizontal"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="fill_parent"

                android:background="#58a3c1"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:orientation="vertical"
                    android:layout_weight="50"
                    android:layout_marginLeft="20dp"
                    android:gravity="center"
                    android:layout_height="wrap_content">
                    <ImageButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher"
                        />
                    <TextView
                        android:gravity="center"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Administration"
                        />
                </LinearLayout>
                <LinearLayout
                    android:layout_weight="50"
                    android:layout_width="fill_parent"
                    android:orientation="vertical"
                    android:layout_marginLeft="20dp"
                    android:gravity="center"
                    android:layout_height="wrap_content">
                    <ImageButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher"
                        />
                    <TextView
                        android:gravity="center"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Administration"
                        />
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

    </android.support.v7.widget.CardView>
    <android.support.v7.widget.CardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/card_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff0"
        android:layout_margin="8dp">
        <LinearLayout
            android:layout_width="fill_parent"
            android:orientation="horizontal"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="fill_parent"

                android:background="#58a3c1"
                android:layout_height="wrap_content">

                <LinearLayout
                    android:layout_width="fill_parent"
                    android:orientation="vertical"
                    android:layout_weight="50"
                    android:layout_marginLeft="20dp"
                    android:gravity="center"
                    android:layout_height="wrap_content">
                    <ImageButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher"
                        />
                    <TextView
                        android:gravity="center"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Administration"
                        />
                </LinearLayout>
                <LinearLayout
                    android:layout_weight="50"
                    android:layout_width="fill_parent"
                    android:orientation="vertical"
                    android:layout_marginLeft="20dp"
                    android:gravity="center"
                    android:layout_height="wrap_content">
                    <ImageButton
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@mipmap/ic_launcher"
                        />
                    <TextView
                        android:gravity="center"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Administration"
                        />
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>

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

將所有內容放入cardview的scrollview中。

那應該允許滾動。

將cardview參數從wrap_content更改為fixed->小於內部內容的大小,以查看發生滾動

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM