【问题标题】:Fill CardView inside screen area在屏幕区域内填充 CardView
【发布时间】:2016-12-18 19:48:09
【问题描述】:

在我的 android 应用程序中,我是一个片段,我想在其中显示给 CardViews。这两个 CardView 应该填满整个屏幕区域。在 cardview 元素内显示的图像是非常大的图像,同样应该缩小以显示在 cardview 内。我无法用以下代码填充整个屏幕区域并使卡片视图可点击。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.myFirstApp.app1.cardviewFragment">

    <!-- TODO: Update blank fragment layout -->

    <!--<android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scrollbars="horizontal"
    android:background="@android:color/holo_blue_bright" ></android.support.v7.widget.RecyclerView>-->
    <LinearLayout android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp" android:background="@color/colorAccent">
        <android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/card_view1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            card_view:cardUseCompatPadding="true"
            card_view:cardCornerRadius="8dp"
            android:layout_marginBottom="16dp">

            <LinearLayout android:orientation="vertical"
                android:id="@+id/display_card_view_linearLayout1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/display_name1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="13sp"
                    android:text="@string/app_name"
                    android:textColor="#ffffff"
                    android:paddingBottom="8dp"
                    android:paddingTop="8dp"
                    android:gravity="center_horizontal"
                    android:layout_alignParentBottom="true"
                    android:background="#1976D2"/>
                <ImageView
                    android:id="@+id/display_image1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:contentDescription="@string/action_settings"
                    android:scaleType="fitCenter" />
                <TextView
                    android:id="@+id/display_information1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textSize="13sp"
                    android:text="Card View Footer"
                    android:textColor="#ffffff"
                    android:layout_below="@+id/display_image1"
                    android:paddingBottom="8dp"
                    android:paddingTop="8dp"
                    android:gravity="center_horizontal"
                    android:layout_alignParentBottom="true"
                    android:background="#1976D2"/>

            </LinearLayout>

        </android.support.v7.widget.CardView>
        <android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/card_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            card_view:cardUseCompatPadding="true"
            card_view:cardCornerRadius="8dp"
            android:layout_marginBottom="16dp">

            <LinearLayout android:orientation="vertical"
                android:id="@+id/display_card_view_linearLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <TextView
                    android:id="@+id/display_name2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="13sp"
                    android:text="@string/app_name"
                    android:textColor="#ffffff"
                    android:paddingBottom="8dp"
                    android:paddingTop="8dp"
                    android:gravity="center_horizontal"
                    android:layout_alignParentBottom="true"
                    android:background="#1976D2"/>
                <ImageView
                    android:id="@+id/display_image2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:contentDescription="@string/action_settings"
                    android:scaleType="fitCenter" />
                <TextView
                    android:id="@+id/display_information2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textSize="13sp"
                    android:text="Card View Footer"
                    android:textColor="#ffffff"
                    android:layout_below="@+id/display_image2"
                    android:paddingBottom="8dp"
                    android:paddingTop="8dp"
                    android:gravity="center_horizontal"
                    android:layout_alignParentBottom="true"
                    android:background="#1976D2"/>

            </LinearLayout>

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

</FrameLayout>

如何让 CardView 填满整个区域并使其可点击?

提前致谢,

IamHuM

【问题讨论】:

    标签: android android-layout android-fragments android-cardview


    【解决方案1】:

    试着把它放在cardview中:

    android:layout_margin="0dp"
    

    我不知道这是否适合你,但在我的一个应用程序中,你可以在设置活动布局中查看代码GitHub code,我使用全宽卡片视图。

    【讨论】:

    • 我建议你扩展你的答案,包括解释为什么这应该起作用。
    • 我不知道这是否适合您,但在我的一个应用程序中,您可以在设置活动布局中查看代码GitHub code,我使用全宽卡片视图。
    • 好的,所以请将您的评论合并到您的答案中(点击“编辑”)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-10-08
    • 1970-01-01
    • 2016-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-08
    相关资源
    最近更新 更多