重构为AndroidX后,布局预览无法正常工作

时间:2019-02-14 13:50:32

标签: android layout androidx

最近,我将项目更新为AndroidX,现在我的某些布局在布局预览中不显示任何内容。

like this

还有一个我不理解的错误。

渲染期间引发异常:16(详细信息)
提示:尝试刷新布局。

这是其中一种布局:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/scrollViewProfileActivity"
            style="@style/matchMatchVertical">

    <LinearLayout style="@style/matchWrapVertical"
                  android:padding="20dp">

        <ImageView android:layout_width="match_parent"
                   android:layout_height="70dp"
                   app:srcCompat="@drawable/logo"
                   android:contentDescription="@string/todo"/>

        <LinearLayout style="@style/matchWrapVertical"
                      android:layout_marginEnd="50dp"
                      android:layout_marginTop="20dp"
                      android:layout_marginStart="50dp">

            <com.google.android.material.textfield.TextInputLayout style="@style/editTextSignUp">
                <com.google.android.material.textfield.TextInputEditText android:hint="@string/name"
                                                                         android:id="@+id/editTextFirstNameProfileActivity"
                                                                         style="@style/editTextSignUp"
                                                                         android:inputType="textPersonName"/>
            </com.google.android.material.textfield.TextInputLayout>


            <com.google.android.material.textfield.TextInputLayout style="@style/editTextSignUp">
                <com.google.android.material.textfield.TextInputEditText android:hint="@string/lastName"
                                                                         android:inputType="textPersonName"
                                                                         style="@style/editTextSignUp"
                                                                         android:id="@+id/editTextLastNameProfileActivity"/>
            </com.google.android.material.textfield.TextInputLayout>

            <com.google.android.material.textfield.TextInputLayout style="@style/editTextSignUp">
                <com.google.android.material.textfield.TextInputEditText android:hint="@string/cantChangeMobile"
                                                                         android:inputType="phone"
                                                                         style="@style/editTextSignUp"
                                                                         android:enabled="false"
                                                                         android:id="@+id/editTextMobileProfileActivity"/>
            </com.google.android.material.textfield.TextInputLayout>

            <com.google.android.material.textfield.TextInputLayout style="@style/editTextSignUp">
                <com.google.android.material.textfield.TextInputEditText android:hint="@string/EmergencyMobile"
                                                                         android:inputType="phone"
                                                                         style="@style/editTextSignUp"
                                                                         android:id="@+id/editTEmergencyMobileProfileActivity"/>
            </com.google.android.material.textfield.TextInputLayout>

            <com.google.android.material.textfield.TextInputLayout style="@style/editTextSignUp">
                <com.google.android.material.textfield.TextInputEditText android:hint="@string/optionalEmail"
                                                                         android:inputType="textEmailAddress"
                                                                         style="@style/editTextSignUp"
                                                                         android:maxLength="35"
                                                                         android:id="@+id/editTextEmailProfileActivity"/>
            </com.google.android.material.textfield.TextInputLayout>

            <com.google.android.material.textfield.TextInputLayout style="@style/editTextSignUp">
                <com.google.android.material.textfield.TextInputEditText android:hint="@string/cantChangeNationalId"
                                                                         android:inputType="number"
                                                                         style="@style/editTextSignUp"
                                                                         android:enabled="false"
                                                                         android:id="@+id/editTextIDProfileActivity"/>
            </com.google.android.material.textfield.TextInputLayout>

            <EditText android:hint="@string/birthDate"
                      android:layout_height="40dp"
                      android:gravity="center"
                      android:textSize="16sp"
                      android:background="@drawable/border_circle"
                      style="@style/editTextSignUp"
                      android:id="@+id/textViewBirthDateProfileActivity"/>

            <ir.org.httpids.diabet.util.SwitchMultiButton
                    android:id="@+id/switchButtonGenderProfileActivity"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:padding="8dp"
                    app:strokeRadius="20dp"
                    app:strokeWidth="1dp"
                    app:selectedTab="0"
                    app:selectedColor="@color/colorPrimary"
                    app:switchTabs="@array/gender"
                    app:textSize="14sp"/>

            <TextView android:layout_width="match_parent"
                      android:text="@string/pregnancyStatus"
                      android:layout_marginTop="20dp"
                      android:id="@+id/textViewPregnancyProfileActivity"
                      style="@style/textView18Grey"
                      android:layout_height="wrap_content"/>

            <ir.org.httpids.diabet.util.SwitchMultiButton
                    android:id="@+id/switchButtonPregnancyProfileActivity"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="7dp"
                    android:padding="8dp"
                    app:strokeRadius="20dp"
                    app:strokeWidth="1dp"
                    app:selectedTab="0"
                    app:selectedColor="@color/colorPrimary"
                    app:switchTabs="@array/pregnancy"
                    app:textSize="14sp"/>

            <TextView android:layout_width="match_parent"
                      android:text="@string/diabetesStatus"
                      android:layout_marginTop="20dp"
                      style="@style/textView18Grey"
                      android:layout_height="wrap_content"/>

            <ir.org.httpids.diabet.util.SwitchMultiButton
                    android:id="@+id/switchButtonDiabetesStatusProfileActivity"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="7dp"
                    android:padding="8dp"
                    app:strokeRadius="20dp"
                    app:strokeWidth="1dp"
                    app:selectedTab="0"
                    app:selectedColor="@color/colorPrimary"
                    app:switchTabs="@array/have"
                    app:textSize="14sp"/>

            <LinearLayout style="@style/matchMatchVertical"
                          android:visibility="gone"
                          android:id="@+id/linearLayoutDiabetesProfileActivity">

                <TextView android:layout_width="match_parent"
                          android:text="@string/diabetesType"
                          android:layout_marginTop="20dp"
                          style="@style/textView18Grey"
                          android:layout_height="wrap_content"/>

                <TextView android:layout_marginTop="7dp"
                          style="@style/textViewSearch"
                          android:id="@+id/textViewDiabetesTypeProfileActivity"/>

                <TextView android:layout_width="match_parent"
                          android:text="@string/sideEffects"
                          android:layout_marginTop="10dp"
                          style="@style/textView18Grey"
                          android:layout_height="wrap_content"/>

                <TextView android:layout_marginTop="7dp"
                          style="@style/textViewSearch"
                          android:id="@+id/textViewSideEffectsProfileActivity"/>

                <EditText android:hint="@string/diabetesDate"
                          android:layout_height="40dp"
                          android:gravity="center"
                          android:textSize="16sp"
                          android:background="@drawable/border_circle"
                          style="@style/editTextSignUp"
                          android:id="@+id/textViewDiabetesDateProfileActivity"/>

            </LinearLayout>

            <com.google.android.material.textfield.TextInputLayout style="@style/editTextSignUp">
                <com.google.android.material.textfield.TextInputEditText android:hint="@string/optionalDes"
                                                                         style="@style/editTextSignUp"
                                                                         android:maxLength="100"
                                                                         android:id="@+id/editTextDescriptionProfileActivity"/>
            </com.google.android.material.textfield.TextInputLayout>

        </LinearLayout>

        <Button android:text="@string/signUp"
                style="@style/mainButton"
                android:layout_marginTop="30dp"
                android:layout_height="wrap_content"
                android:id="@+id/buttonProfileActivity"/>

    </LinearLayout>

</ScrollView>

唯一的区别是支持库已更改为androidX库。

1 个答案:

答案 0 :(得分:0)

尝试使用文件->在Android Studio中使缓存无效/重新启动。