简体   繁体   English

如何创建卡片视图?

[英]How can i create a card view?

I am adding a card View in a simple activity, as i write it's code, Android studio start showing an error "Rendering Problem" How can i come over it ?我正在一个简单的活动中添加一个卡片视图,当我编写它的代码时,Android studio 开始显示错误“渲染问题”我怎么能克服它? Here i'm attaching my code..在这里我附上我的代码..

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.sj.digitalapplications1.MainActivity"
    tools:showIn="@layout/activity_main">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Digital Application Android Team"
        android:textSize="32sp"
        android:gravity="center"
        android:id="@+id/textView" />

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/cv"
        >
    </android.support.v7.widget.CardView>

</RelativeLayout>

Add dependency in your build.gradle.在 build.gradle 中添加依赖项。

dependencies {       
    compile 'com.android.support:cardview-v7:23.1.1'    
}

Or Right click on Project-> Go to module settings->Open Dependencies Tab->click on plus sign on right corner->select library dependency->select cardview library或右键单击项目-> 转到模块设置-> 打开依赖项选项卡-> 单击右上角的加号-> 选择库依赖项-> 选择cardview 库

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/smartbro_perc"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"/>

You have missed these thing, please add the below code.你错过了这些东西,请添加下面的代码。

  1. In your xml在你的 xml

     xmlns:card_view="http://schemas.android.com/apk/res-auto Add it
  2. In build.gradle (Module app)在 build.gradle(模块应用程序)中

    implementation 'com.android.support:cardview-v7:26.1.0' // this version or above version ++

compile 'com.android.support:cardview-v7:21.0.0'编译'com.android.support:cardview-v7:21.0.0'

Use this as a dependency in your build.gradle file.将其用作 build.gradle 文件中的依赖项。 This might work in Android Studio 1.5.1.这可能适用于 Android Studio 1.5.1。

PS: I assume that you are using SDK Version >=21 PS:我假设您使用的是 SDK 版本 >=21

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM