I want to use Cardview to make the screen more beautiful only cardView works similar to a listview?

Asked

Viewed 289 times

0

And I want to take dynamic data to show on the screen. Dynamic data that will come from a webservice.

So I need to use Recyclerview with Cardview Layout to make the data dynamic?

How can I make my Cardview as if it were elements of a Listview?

1 answer

2


First, after the project is created, go to the file build.gradle (app) and add the following dependencies:

compile ‘com.android.support:cardview-v7:21.0.+’
compile ‘com.android.support:recyclerview-v7:21.0.+’

Then in your list there is an item, which is probably set in your Adapter. The following code example shows how to include a widget CardView in the layout:

<LinearLayout 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"
    ... >
    <!-- Um CardView com um TextView dentro -->
    <android.support.v7.widget.CardView
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="200dp"
        android:layout_height="200dp"
        card_view:cardCornerRadius="4dp">

        <TextView
            android:id="@+id/info_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v7.widget.CardView>
</LinearLayout>

See more details in the documentation on how to create lists and cards.

  • Hi Ack, so when you refer to the list you meant to Listview or recyclerview?

  • Which one you want of the two, which you are currently using. To better adapt to your scenario, it would be good for you to add your code.

  • I think I understand... I have a listview and each element of the list I am directed to a screen and from there I can make some modification...I wish my Listview had the style of Cardview...

  • I have a layout that has two textView and these elemesos are shown on each element of the list... and I inflate with the layout of the listview

  • I’ll modify it and show it here...

  • 1

    @Aline It’s easy! Each item in your project has a layout. Each person puts the name you think best, example: row.xml, item.xml, meu_item.xlm, item_list.xml. This same layout that has textView will change and put the cardview. There you insert the two Textview inside the cardView and kill the riddle.

  • That’s when I thought

  • Wait I need to put xmlns:card_view="http://schemas.android.com/apk/res-auto" in all my Linear layout besides cardView? Because I have a textview that sits within two Linearlayout

  • 1

    @Aline See the change.

  • 1

    @Aline leaving only in Linearlayout, already solves the problem

  • It did not work no. I needed to show 10 items from a list, only that appeared only 8 elements.

  • 1

    @Aline the problem there is no longer Cardview understand?! This answer meets very well what you want. So I suggest asking another question, to know why you are not listing these 10 items. You pull from where these items. If you are really going to ask another question, try to detail your problem better by inserting part of your code.

  • I fixed it. Thanks it all worked out!

  • 1

    @Aline =) That’s it ae! o/

Show 9 more comments

Browser other questions tagged

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