How to use CardView + ListView in the same layout?

1

I am interested in creating a layout divided into two parts, at the top a CardView (I do not have to use RecyclerView , since I only need one) I leave this image as an example:

The problem I have is that the CardView overlaps the ListView that I would like to add below, occupying the lower half of the screen. Is the implementation of these two classes correct for the use I want to give him? I leave my layout below:

<LinearLayout
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"
android:orientation="horizontal"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin">

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <android.support.v7.widget.CardView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        card_view:cardCornerRadius="@dimen/cardview_default_radius"
        card_view:cardElevation="@dimen/cardview_default_elevation"
        card_view:cardUseCompatPadding="true">

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

            <ImageView
                android:id="@+id/foto"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingBottom="8dp"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="24dp">


                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/nombre"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentStart="true"
                        android:layout_alignParentLeft="true"
                        android:paddingBottom="8dp"
                        android:text="texto2"
                        android:textAppearance="@style/TextAppearance.AppCompat.Headline" />

                </RelativeLayout>

                <TextView
                    android:id="@+id/descripcion"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="texto3">

            </LinearLayout>

        </LinearLayout>

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

</FrameLayout>

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ListView
        android:focusableInTouchMode="false"
        android:drawSelectorOnTop="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/listViewId"
        android:fastScrollEnabled="true"
        android:stackFromBottom="false" />
</LinearLayout>

Thank you very much in advance

    
asked by M. Mariscal 01.03.2016 в 19:35
source

1 answer

2

According to your Layout , the CardView would contain the TextView and it would be:

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">


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

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


            <ImageView
                android:id="@+id/foto"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:paddingBottom="8dp"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="24dp">


                <RelativeLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <TextView
                        android:id="@+id/nombre"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_alignParentLeft="true"
                        android:layout_alignParentStart="true"
                        android:paddingBottom="8dp"
                        android:text="texto2"
                        android:textAppearance="@style/TextAppearance.AppCompat.Headline" />

                </RelativeLayout>

                <TextView
                    android:id="@+id/descripcion"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="texto3" />

            </LinearLayout>


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

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ListView
                android:id="@+id/listViewId"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:drawSelectorOnTop="true"
                android:fastScrollEnabled="true"
                android:focusableInTouchMode="false"
                android:stackFromBottom="false" />
        </LinearLayout>


    </LinearLayout>
</FrameLayout>

This is an example of how it would look like:

    
answered by 01.03.2016 / 19:47
source