Отображение ошибок на CardCornerRadius и CardElevation - PullRequest
0 голосов
/ 30 мая 2020

Я определил свой макет следующим образом:

<?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>

Я получаю следующие ошибки в CardCornerRadius и CardElevation:

Android связывание ресурсов сбой D: \ AndroidStudioProjects \ App \ app \ src \ main \ res \ layout \ activity_main. xml: 12: AAPT: error: attribute cardCornerRadius (aka com.ksaitarun.app:cardCornerRadius) не найден.

D: \ AndroidStudioProjects \ App \ app \ src \ main \ res \ layout \ activity_main. xml: 12: AAPT: error: attribute cardElevation (aka com.ksaitarun.app:cardElevation) не найден.

Ответы [ 2 ]

1 голос
/ 30 мая 2020

Убедитесь, что вы добавили эту библиотеку в 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 голос
/ 30 мая 2020

Я не думаю, что что-то не так, но что-то, что может помочь, - это просто использование одного пространства имен для всех ваших настраиваемых атрибутов. В родительском контейнере вы используете пространство имен приложения

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">
...