1

I try to do card view but i can't understand how to do a scrolling page with textview and a webview. Can someone show me the basic code of Card View.

<TextView
            android:id="@+id/textView4"
            android:layout_width="432dp"
            android:layout_height="510dp"
            android:text="TextView" />

        <WebView
            android:id="@+id/webview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

I want that the page of my app that his a text view and a webview that the user can scroll. So I think that I can do that with cardview, but I can't understand the code of cardview that I saw on videos. How can I use this function with only a textview and a cardview?

I have looked some videos on CardView but I can't used their code for what I want to do. Me I have only a text view and a webview that I want that the user can scroll. Would someone show some basic code of card view, and explain what it does?

Malavan P
  • 68
  • 6

1 Answers1

2

Add the card view dependencies

   dependencies {
            implementation 'androidx.cardview:cardview:1.0.0'
   }

Add the cardview in your layout

<androidx.cardview.widget.CardView
        android:id="@+id/card_view"
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        card_view:cardBackgroundColor="@color/grey_300"
        card_view:cardCornerRadius="10dp"
        card_view:cardElevation="5dp"
        card_view:cardUseCompatPadding="true">
<TextView
            android:id="@+id/textView4"
            android:layout_width="432dp"
            android:layout_height="510dp"
            android:text="TextView" />

        <WebView
            android:id="@+id/webview"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
</<androidx.cardview.widget.CardView>
Malavan
  • 789
  • 7
  • 27
  • when i compile i have this error The project 'info' may be using a version of Gradle that does not contain the method. Open Gradle wrapper file but thanks for helping but i saw on video that there his a java code do we need to put it or not? –  Oct 23 '19 at 11:12
  • in what dependencies i need to put the compile code module app or Project info –  Oct 23 '19 at 11:16
  • Inside the app dependencies – Malavan Oct 23 '19 at 11:22
  • cardview-v7:21.0.0-rc1 Really?? There are the v28.0.0, the androidx version and the [material components version](https://stackoverflow.com/questions/53089633/how-to-add-cardview-in-layout-xml-in-androidx/57833454#57833454), but pls not a very very old RC. – Gabriele Mariotti Oct 23 '19 at 11:44
  • thanks to help me i will let you know if i have any diffuclties –  Oct 23 '19 at 11:52
  • @Gabriele Not everyone using latest verion. By the way updated it – Malavan Oct 23 '19 at 11:52
  • hello, i resolved the code i have the cardview that appear but when i scroll nothing change i think it's because i need the java code sorry to be annoying, but if someone can help me i would be happy. –  Oct 23 '19 at 20:41