[英]My (Specific) layout causes Android Studio XML Layout Preview to keep on loading and not displaying the preview
I am making a layout which contains CardView and nested Linear Layouts.我正在制作一个包含 CardView 和嵌套线性布局的布局。 When I made the layout for the first time it works fine and the preview window is also displaying the changes.
当我第一次制作布局时,它工作正常,预览窗口也显示了更改。 After a day when I open android Studio the preview window keep saying "Waiting for build to finish".
一天后,当我打开 android Studio 时,预览窗口一直说“等待构建完成”。 So I thought that it is bug related to IDE.
所以我认为这是与IDE相关的错误。
I tried all the solutions that are recommended here:我尝试了这里推荐的所有解决方案:
But I found out that issue was with my layout beacuse I deleted the layout rebuild the project and preview works fine again.但是我发现问题出在我的布局上,因为我删除了布局重建项目并且预览再次正常工作。 Now I tried to make the same layout again from start but it still happens again.
现在我试图从头开始再次制作相同的布局,但它仍然再次发生。 It is very strange for me as my layout is simple, I have created Similar layouts before with no issue whatsoever.
这对我来说很奇怪,因为我的布局很简单,我之前创建过类似的布局,没有任何问题。 I am using the Latest Api Version 29, with latest build tools and latest Android Studio.
我正在使用最新的 Api 版本 29,以及最新的构建工具和最新的 Android Studio。
Here is my layout code:这是我的布局代码:
<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>
The cause of the issue is Slider.问题的原因是滑块。 I'm trying to solve it too but still unsuccessful.
我也在尝试解决它,但仍然没有成功。
Sorry for late reply... Use AppCompatSlider
or simply replace it by the traditional Seekbar
.抱歉回复晚了...使用
AppCompatSlider
或简单地将其替换为传统的Seekbar
。 I also faced the same issue with material slider.我在材质滑块上也遇到了同样的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.