在CardCornerRadius和CardElevation上显示错误

问题描述 投票:0回答:2

我已如下定义布局:

<?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:background="@drawable/background"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    tools:context=".MainActivity">

    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="32dp"
        card_view:cardCornerRadius="8dp"
        card_view:cardElevation="16dp">

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:padding="16dp">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/question1title"
                    style="@style/questionTitle"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/question1"
                    style="@style/questionAndAnswers"/>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">
                    <CheckBox
                        android:id="@+id/checkboxQuest1AnswerMario"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/answerMario"/>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">
                    <CheckBox
                        android:id="@+id/checkboxQuest1AnswerDonkey"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/answerDonkeyKong"/>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">
                    <CheckBox
                        android:id="@+id/checkboxQuest1AnswerPortal"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/answerPortal"/>
                </LinearLayout>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/question2title"
                    style="@style/questionTitle"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/question2"
                    style="@style/questionAndAnswers"/>

                <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <RadioButton android:id="@+id/radio_1979"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/answer1979"/>
                    <RadioButton android:id="@+id/radio_1989"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/answer1989"/>
                    <RadioButton android:id="@+id/radio_1999"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/answer1999"/>
                </RadioGroup>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/question3title"
                    style="@style/questionTitle"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/question3"
                    style="@style/questionAndAnswers"/>

                <EditText
                    android:id="@+id/answerInputUserLastName"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:hint="@string/LastNameLaraHint"
                    android:inputType="text"
                    android:maxLength="10"/>


                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/question4title"
                    style="@style/questionTitle"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/question4"
                    style="@style/questionAndAnswers"/>

                <RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <RadioButton android:id="@+id/radio_bioShock"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/answerBioShock"/>
                    <RadioButton android:id="@+id/radio_borderlands"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/answerBorderlands"/>
                    <RadioButton android:id="@+id/radio_portal"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/answerPortal"/>
                </RadioGroup>


                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/question5title"
                    style="@style/questionTitle"/>

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/question5"
                    style="@style/questionAndAnswers"/>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">
                    <CheckBox
                        android:id="@+id/checkboxQuest5GameBoy"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/answerGameBoy"/>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">
                    <CheckBox
                        android:id="@+id/checkboxQuestPSP"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/answerPSP"/>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">
                    <CheckBox
                        android:id="@+id/checkboxQuest5Wii"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="@string/answerWii"/>
                </LinearLayout>

                <Button
                    android:id="@+id/submitButton"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/submit"
                    android:layout_gravity="center_horizontal"/>
            </LinearLayout>

        </ScrollView>

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

</RelativeLayout>

我在CardCornerRadiusCardElevation中遇到以下错误:

Android资源链接失败 D:\ AndroidStudioProjects \ App \ app \ src \ main \ res \ layout \ activity_main.xml:12: AAPT:错误:属性cardCornerRadius(aka com.ksaitarun.app:cardCornerRadius)。

D:\ AndroidStudioProjects \ App \ app \ src \ main \ res \ layout \ activity_main.xml:12: AAPT:错误:属性cardElevation(又名 com.ksaitarun.app:cardElevation)找不到。

android android-studio android-layout android-cardview
2个回答
1
投票

确保已将此库添加到build.gradle文件中

implementation 'com.android.support:cardview-v7:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:design:28.0.0'

1
投票

我不认为有什么问题,但是可能对您所有的自定义属性都使用一个名称空间可能会有所帮助。在父容器中,您正在使用应用程序名称空间

xmlns:app="http://schemas.android.com/apk/res-auto"

因此,您需要在cardview属性中使用该名称空间。只需将card_view替换为app并删除CardView中的名称空间。

<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:layout_gravity="center"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="32dp"
    app:cardCornerRadius="8dp"
    app:cardElevation="16dp">
© www.soinside.com 2019 - 2024. All rights reserved.