Cardview And Horizontalscrollview

Asked

Viewed 69 times

1

How to do for all cards are the same height as scroll horizontally?

Fragment:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/app_bg">


<RelativeLayout
    android:id="@+id/main"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/adView"
        android:layout_alignParentTop="true">

        <RelativeLayout
            android:id="@+id/contentgone"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <RelativeLayout
                android:id="@+id/linear_title_video"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/slider"
                android:layout_marginBottom="1dp"
                android:layout_marginLeft="3dp"
                android:layout_marginRight="3dp"
                android:layout_marginTop="5dp"
                android:orientation="horizontal"
                android:background="@color/white"
                android:padding="5dp">

                <TextView
                    android:id="@+id/text_title_latest"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/latest_video"
                    android:gravity="start|center_vertical"
                    android:layout_alignParentStart="true"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:textColor="@color/black"
                    android:textSize="18sp"
                    android:textStyle="bold" />

                <android.support.v7.widget.CardView
                    android:id="@+id/card_view2"
                    android:layout_width="60dp"
                    android:layout_height="30dp"
                    android:layout_alignParentEnd="true"
                    card_view:cardBackgroundColor="@color/colorPrimary"
                    card_view:cardCornerRadius="2dp"
                    card_view:cardUseCompatPadding="false"
                    card_view:elevation="5dp">

                    <Button
                        android:id="@+id/btn_more"
                        android:layout_width="60dp"
                        android:layout_height="30dp"
                        android:layout_gravity="end"
                        android:layout_alignParentRight="true"
                        android:layout_centerVertical="true"
                        android:background="@android:color/transparent"
                        android:text="@string/more_btn"
                        android:textColor="@color/white" />
                </android.support.v7.widget.CardView>
            </RelativeLayout>


            <RelativeLayout
                android:id="@+id/rel_c_content_video"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/linear_title_video"
                android:gravity="center"
                android:orientation="horizontal">

                <HorizontalScrollView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content">
                        <GridView
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:id="@+id/ultimos_episodios"
                            android:layout_gravity="center"/>
                    </LinearLayout>
                </HorizontalScrollView>
            </RelativeLayout>   
        </RelativeLayout>
    </ScrollView>

</RelativeLayout>

<ProgressBar
    android:id="@+id/progressBar"
    style="?android:attr/progressBarStyleLarge"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:indeterminate="true"
    android:indeterminateTint="@color/colorPrimary"
    android:indeterminateTintMode="src_atop"
    android:visibility="gone" />

Cardview

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        card_view:cardBackgroundColor="@color/white"
        card_view:cardCornerRadius="2dp"
        card_view:cardUseCompatPadding="false"
        card_view:elevation="5dp">

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

            <RelativeLayout
                android:id="@+id/imgsec"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true">

                <android.support.v7.widget.CardView
                    android:id="@+id/card_view2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    card_view:cardBackgroundColor="@color/colorPrimary"
                    card_view:cardCornerRadius="2dp"
                    card_view:cardUseCompatPadding="false"
                    card_view:elevation="5dp">

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

                        <com.example.util.CatSquareImageView
                            android:id="@+id/image_home"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:contentDescription="@string/app_name"
                            android:padding="2dp"
                            android:scaleType="fitXY"
                            android:src="@drawable/placeholder" />

                        <LinearLayout
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_alignBottom="@+id/image"
                            android:layout_alignParentEnd="true"
                            android:layout_alignParentRight="true"
                            android:layout_marginBottom="2dp"
                            android:layout_marginRight="1.5dp"
                            android:orientation="vertical">

                        </LinearLayout>

                        <ImageView
                            android:id="@+id/imageView"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_centerHorizontal="true"
                            android:layout_centerVertical="true"
                            card_view:srcCompat="@drawable/ic_play" />
                    </RelativeLayout>
                </android.support.v7.widget.CardView>


            </RelativeLayout>

            <TextView
                android:id="@+id/primary_text_home"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="start"
                android:padding="2dp"
                android:text=""
                android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
                android:textColor="@color/black" />

            <TextView
                android:id="@+id/secondary_text_nome"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="start"
                android:paddingBottom="2dp"
                android:paddingLeft="2dp"
                android:text=""
                android:drawableTint="@color/colorPrimary"
                android:drawableLeft="@drawable/ic_remove_red_eye_black_24dp"
                android:drawablePadding="8px"
                android:textColor="@color/black_light" />

        </LinearLayout>

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

</LinearLayout>

As the text visualization can have more than one line, it ends up breaking the layout.

Card View Image

  • Have you tried changing the layout_height for match_parent?

  • Yes, it doesn’t work, I’m lost I don’t know what else to try.

  • But what behavior do you expect it to have? Limit the number of lines?

No answers

Browser other questions tagged

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