我正在制作一个包含CardView和嵌套线性布局的布局。当我第一次制作布局时,它可以正常工作,并且预览窗口也显示更改。在打开android Studio的一天后,预览窗口会继续显示“等待构建完成”。因此,我认为这是与IDE相关的错误。
我尝试了这里推荐的所有解决方案:
但是我发现问题出在我的布局上,因为我删除了布局以重新生成项目,并且预览再次正常运行。现在,我尝试从头开始再次制作相同的布局,但仍然会再次发生。对我来说,这很奇怪,因为我的布局很简单,我之前创建过类似的布局,没有任何问题。我正在使用最新的Api版本29,以及最新的构建工具和最新的Android Studio。
这是我的布局代码:
<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="@color/light"
tools:context=".Ui.Setting">
<androidx.appcompat.widget.Toolbar
android:id="@+id/setting_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/light"
android:minHeight="?attr/actionBarSize"
android:theme="@style/ToolbarTheme"
app:title="SETTINGS"
app:titleMarginStart="40dp"
app:titleTextColor="@color/dark" />
<com.google.android.material.textview.MaterialTextView
android:id="@+id/accessibility"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/setting_toolbar"
android:layout_marginStart="10dp"
android:padding="10dp"
android:text="@string/accessibility"
android:textColor="@color/dark"
android:textSize="18sp" />
<androidx.cardview.widget.CardView
android:id="@+id/accessibility_card"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/accessibility"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
app:cardCornerRadius="8dp"
app:cardElevation="10dp"
app:contentPadding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:baselineAligned="false">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_vertical">
<com.google.android.material.textview.MaterialTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="1"
android:text="@string/grey_scale" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
app:useMaterialThemeColors="true" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@android:color/darker_gray" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center_vertical">
<com.google.android.material.textview.MaterialTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_weight="0.5"
android:text="@string/text_size" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="3">
<com.google.android.material.textview.MaterialTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:gravity="end"
android:text="@string/aminus" />
<com.google.android.material.slider.Slider
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2" />
<com.google.android.material.textview.MaterialTextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="10dp"
android:layout_weight="0.5"
android:gravity="end"
android:text="@string/aplus" />
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
dependencies {
// ...
implementation 'com.google.android.material:material:<version>'
// ...
}