Card View with Scroll

Asked

Viewed 426 times

0

People started to make my application, but I forgot to put a scrollbar for it to slide. Result, the cardview went past the screen. I tried to add the Scrollview tag at first but it doesn’t work.

Will I have to redo everything from scratch with Fragments ?

<?xml version="1.0" encoding="utf-8"?>

android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.jnior.decorus.DetalhesCatalogo">


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:id="@+id/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.CardView
        android:id="@+id/card_view8a6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        android:background="@color/colorPrimaryDark"
        android:paddingBottom="@dimen/activity_vertical_margin"
        card_view:cardCornerRadius="2dp"
        card_view:contentPadding="10dp">

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


            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:src="@mipmap/user_clientes" />

            <TextView
                android:id="@+id/textView32"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="19dp"
                android:layout_marginStart="19dp"
                android:layout_toEndOf="@+id/imageView2"
                android:layout_toRightOf="@+id/imageView2"
                android:text="@string/cliente"
                android:textAppearance="?android:attr/textAppearanceLarge" />


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

    <android.support.v7.widget.CardView
        android:id="@+id/card_view8"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        android:background="@color/colorPrimaryDark"
        android:paddingBottom="@dimen/activity_vertical_margin"
        card_view:cardCornerRadius="2dp"
        card_view:contentPadding="10dp">

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


            <ImageView
                android:id="@+id/imageView2a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:src="@mipmap/ic_data" />

            <TextView
                android:id="@+id/textView32a"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="19dp"
                android:layout_marginStart="19dp"
                android:layout_toEndOf="@+id/imageView2a"
                android:layout_toRightOf="@+id/imageView2a"
                android:text="@string/data"
                android:textAppearance="?android:attr/textAppearanceLarge" />


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

    <TextView
        android:id="@+id/textView33"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/linearLayout"
        android:layout_margin="5dp"
        android:text="@string/item"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <android.support.v7.widget.CardView
        android:id="@+id/card_view8a"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        android:background="@color/colorPrimaryDark"
        android:paddingBottom="@dimen/activity_vertical_margin"
        card_view:cardCornerRadius="2dp"
        card_view:contentPadding="10dp">

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


            <TextView
                android:id="@+id/textView32aa"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="19dp"
                android:layout_marginStart="19dp"
                android:text="@string/add_itens"
                android:textAppearance="?android:attr/textAppearanceLarge" />

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


    <android.support.v7.widget.CardView
        android:id="@+id/card_view_1"
        android:layout_width="fill_parent"
        android:layout_height="180dp"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        card_view:cardCornerRadius="2dp"
        card_view:contentPadding="10dp">

        <RelativeLayout
            android:id="@+id/Vendas"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <ImageView
                android:id="@+id/imageView"
                android:layout_width="130dp"
                android:layout_height="95dp"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:src="@mipmap/top" />

            <TextView
                android:id="@+id/textView12"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_toEndOf="@+id/imageView"
                android:layout_toRightOf="@+id/imageView"
                android:text="Polpa Hidratante para Mãos e Unhas Castanha Ekos"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView13"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/textView30"
                android:layout_alignBottom="@+id/textView30"
                android:layout_toEndOf="@+id/imageView"
                android:layout_toRightOf="@+id/imageView"
                android:text="Ref: 294411"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView29"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/imageView"
                android:layout_toEndOf="@+id/imageView"
                android:layout_toRightOf="@+id/imageView"
                android:text="Pág.: 53"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView31"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_alignTop="@+id/textView29"
                android:text="Preço: 185,00"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView30"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/textView31"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:text="600 ml"
                android:textAppearance="?android:attr/textAppearanceSmall" />

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

    <TextView
        android:id="@+id/textView33aa"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/linearLayout"
        android:layout_margin="5dp"
        android:text="@string/valores"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <android.support.v7.widget.CardView
        android:id="@+id/card_view_16"
        android:layout_width="fill_parent"
        android:layout_height="180dp"
        android:layout_gravity="center"
        android:layout_margin="5dp"
        card_view:cardCornerRadius="2dp"
        card_view:contentPadding="10dp">

        <RelativeLayout
            android:id="@+id/Vendas6"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">

            <ImageView
                android:id="@+id/imageView6"
                android:layout_width="130dp"
                android:layout_height="95dp"
                android:layout_alignParentBottom="true"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:src="@mipmap/top" />

            <TextView
                android:id="@+id/textView126"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:layout_toEndOf="@+id/imageView6"
                android:layout_toRightOf="@+id/imageView6"
                android:text="Polpa Hidratante para Mãos e Unhas Castanha Ekos"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <TextView
                android:id="@+id/textView136"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/textView306"
                android:layout_alignBottom="@+id/textView306"
                android:layout_toEndOf="@+id/imageView6"
                android:layout_toRightOf="@+id/imageView6"
                android:text="Ref: 294411"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView296"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/imageView6"
                android:layout_toEndOf="@+id/imageView6"
                android:layout_toRightOf="@+id/imageView6"
                android:text="Pág.: 53"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView316"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_alignTop="@+id/textView296"
                android:text="Preço: 185,00"
                android:textAppearance="?android:attr/textAppearanceSmall" />

            <TextView
                android:id="@+id/textView306"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_above="@+id/textView316"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:text="600 ml"
                android:textAppearance="?android:attr/textAppearanceSmall" />

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


</LinearLayout>

1 answer

1

Add the following code above the first Linearlayout tag

<ScrollView android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

And close the tags at the end of the code

</ScrollView>
  • It didn’t work Leonardo. I did what you suggested and even then Scroll did not work.

  • tries to remove this part of the android code:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.Jnior.decorus.">

  • I’ll try at home. After I talk. Thanks

  • Leonardo, I tried it yesterday and I got it just like you did. Thank you so much for your help.

Browser other questions tagged

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