How can I make Cardview dynamic-sized?

Asked

Viewed 211 times

0

I got a little problem...

I have several Cardsview and their size is static I would like to know how to make this size adaptable to what is on cardView.

Because in a Cardview I have a list that comes data from the database and if the size is static will end up not appearing all records.

How can I make this Cardview adaptable to listview size?

Follow an excerpt from my code:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#DCDCDC"
android:scrollbars="none"
android:fillViewport="true">

    <LinearLayout
        android:id="@+id/hide_layout"
        android:padding="10dp"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.CardView
            android:id="@+id/id_ocorrecia"
            card_view:cardCornerRadius="5dp"
            card_view:cardElevation="2dp"
            android:layout_width="match_parent"
            android:layout_height="380dp"
            android:layout_gravity="center">
            <LinearLayout
                android:layout_gravity="center"
                android:gravity="center"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                    <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">
                        <LinearLayout
                            android:orientation="horizontal"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content">
                            <LinearLayout
                                android:layout_width="0dp"
                                android:layout_weight="5"
                                android:layout_height="wrap_content">
                                <TextView
                                    android:paddingLeft="8dp"
                                    android:paddingTop="12dp"
                                    android:paddingBottom="12dp"
                                    android:layout_marginLeft="8dp"
                                    android:textSize="15dp"
                                    android:textStyle="bold"
                                    android:textColor="@color/preto"
                                    android:text="Ocorrências"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:ems="10"
                                    android:id="@+id/txtEquipe"
                                    />
                            </LinearLayout>
                        </LinearLayout>

                            <LinearLayout
                                android:background="#A9A9A9"
                                android:orientation="horizontal"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                >
                                <LinearLayout
                                    android:layout_marginTop="12dp"
                                    android:layout_marginLeft="5dp"
                                    android:padding="10dp"
                                    android:orientation="horizontal"
                                    android:layout_width="10dp"
                                    android:layout_height="10dp"
                                    android:background="#A9A9A9"
                                    ></LinearLayout>

                                    <LinearLayout
                                        android:layout_width="0dp"
                                        android:layout_weight="8"
                                        android:layout_height="wrap_content">
                                        <TextView
                                            android:textStyle="bold"
                                            android:textColor="@color/preto"
                                            android:textSize="12dp"
                                            android:padding="8dp"
                                            android:text="SERVIÇO"
                                            android:layout_width="match_parent"
                                            android:layout_height="wrap_content"
                                            android:ems="10"
                                            android:id="@+id/ff"
                                            />

                                    </LinearLayout>
                                <LinearLayout
                                    android:layout_weight="4"
                                    android:layout_width="0dp"
                                    android:layout_height="match_parent">
                                    <TextView
                                        android:textColor="@color/preto"
                                        android:textSize="12dp"
                                        android:textStyle="bold"
                                        android:padding="8dp"
                                        android:gravity="center"
                                        android:layout_width="match_parent"
                                        android:layout_height="wrap_content"
                                        android:ems="10"
                                        android:text="TOTAL"
                                        android:id="@+id/txtTotal"
                                        />
                                </LinearLayout>
                                <LinearLayout
                                    android:layout_weight="4"
                                    android:layout_width="0dp"
                                    android:layout_height="match_parent">
                                    <TextView
                                        android:layout_gravity="center"
                                        android:textColor="@color/preto"
                                        android:textSize="12dp"
                                        android:text="EM ATEND."
                                        android:padding="8dp"
                                        android:textStyle="bold"
                                        android:layout_width="match_parent"
                                        android:layout_height="wrap_content"
                                        android:ems="10"
                                        android:id="@+id/txtRecursos"
                                        />
                                </LinearLayout>
                            </LinearLayout>



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

                            <ListView
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:id="@+id/lstOcorrencias"
                                android:divider="@null"
                                android:dividerHeight="0dp"
                                android:listSelector="@android:color/transparent"
                                />
                        </LinearLayout>
                        <LinearLayout
                            android:id="@+id/visivel"
                            android:orientation="horizontal"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content">
                            <LinearLayout
                                android:layout_marginTop="12dp"
                                android:layout_marginLeft="5dp"
                                android:padding="10dp"
                                android:orientation="horizontal"
                                android:layout_width="10dp"
                                android:layout_height="10dp"
                                ></LinearLayout>
                            <LinearLayout
                                android:layout_width="0dp"
                                android:layout_weight="8"
                                android:layout_height="wrap_content">
                                <TextView
                                    android:textColor="@color/preto"
                                    android:textSize="12dp"
                                    android:text="Outros (Demais Serviços)"
                                    android:padding="10dp"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:ems="10"
                                    android:id="@+id/txtOut"
                                    />
                            </LinearLayout>
                            <LinearLayout
                                android:layout_weight="4"
                                android:layout_width="0dp"
                                android:layout_height="match_parent">
                                <TextView
                                    android:padding="10dp"
                                    android:textColor="@color/preto"
                                    android:textSize="12dp"
                                    android:gravity="center"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:ems="10"
                                    android:text=""
                                    android:id="@+id/txtoutTotal"
                                    />
                            </LinearLayout>
                            <LinearLayout
                                android:layout_weight="4"
                                android:layout_width="0dp"
                                android:layout_height="match_parent">
                                <TextView
                                    android:gravity="center"
                                    android:textColor="@color/preto"
                                    android:textSize="12dp"
                                    android:padding="10dp"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:ems="10"
                                    android:text=""
                                    android:id="@+id/txtoutEmAtendimento"
                                    />
                            </LinearLayout>
                        </LinearLayout>
                        <LinearLayout
                            android:background="#A9A9A9"
                            android:orientation="horizontal"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content">
                            <LinearLayout
                                android:layout_marginTop="12dp"
                                android:layout_marginLeft="5dp"
                                android:padding="10dp"
                                android:orientation="horizontal"
                                android:layout_width="10dp"
                                android:layout_height="10dp"
                                android:background="#A9A9A9"
                                >

                            </LinearLayout>
                            <LinearLayout
                                android:layout_width="0dp"
                                android:layout_weight="8"
                                android:layout_height="wrap_content">
                                <TextView
                                    android:paddingLeft="5dp"
                                    android:textColor="@color/preto"
                                    android:textSize="12dp"
                                    android:textStyle="bold"
                                    android:padding="8dp"
                                    android:text="TOTAL GERAL"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:ems="10"
                                    android:id="@+id/txtTotalGeral"
                                    />
                            </LinearLayout>
                            <LinearLayout
                                android:layout_weight="4"
                                android:layout_width="0dp"
                                android:layout_height="match_parent">
                                <TextView
                                    android:textColor="@color/preto"
                                    android:textSize="12dp"
                                    android:gravity="center"
                                    android:textStyle="bold"
                                    android:padding="8dp"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:ems="10"
                                    android:text="0"
                                    android:id="@+id/txtTotalQTD"
                                    />
                            </LinearLayout>
                            <LinearLayout
                                android:layout_weight="4"
                                android:layout_width="0dp"
                                android:layout_height="match_parent">
                                <TextView
                                    android:textColor="@color/preto"
                                    android:textSize="12dp"
                                    android:gravity="center"
                                    android:padding="8dp"
                                    android:textStyle="bold"
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
                                    android:ems="10"
                                    android:text="0"
                                    android:id="@+id/txtTotalGEmAtendimentoQTD"
                                    />
                            </LinearLayout>

                        </LinearLayout>

            </LinearLayout>

            </LinearLayout>
        </android.support.v7.widget.CardView>
</ScrollView>
  • I removed the answer, I really hadn’t noticed that last sentence of yours there. I have no time to see it now, later on if no one puts an answer I try to draft an answer for you. = p

  • The truth is that I have a Scrollview and inside a listview in case cardView is dynamic pq I put as wrap-content as Ack said. Now the problem is that the way it is is only displayed the first record of the list.... the rest is cut...

  • but.... but Ack won’t go away. =(

  • 1

    Really this layout is complicated, moreover, use ListView within a ScrollView is not recommended. It will be a good job, but my recommendation is to use the RecyclerView with a Header and a Footer to encompass all the rest of the layout that is fixed above and below the ListView.

  • Yes the solution was to use Recycleview even all right! It worked!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.