Java Android Studio 3.0布局编辑器/预览器
我正在使用Android Studio 3.0制作一个Android应用程序 但我面临的问题是布局编辑器/预览器工作不正常。它有时不显示任何内容,有时显示带有所有导航按钮的灰色框 这些是截图 我使用的是Java Android Studio 3.0布局编辑器/预览器,java,android,android-layout,layout,android-gradle-plugin,Java,Android,Android Layout,Layout,Android Gradle Plugin,我正在使用Android Studio 3.0制作一个Android应用程序 但我面临的问题是布局编辑器/预览器工作不正常。它有时不显示任何内容,有时显示带有所有导航按钮的灰色框 这些是截图 我使用的是buildToolsVersion'26.0.2',而支持库的版本是23.0.1 任何帮助都会很有帮助 编辑:这是我的XML布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=
buildToolsVersion'26.0.2'
,而支持库的版本是23.0.1
任何帮助都会很有帮助
编辑:这是我的XML布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="100dp"/>
<ImageView
android:id="@+id/logo"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
android:background="@drawable/logo" />
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF"
android:textSize="33dp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_marginBottom="15dp">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="15dp"
android:textColor="#FFFFFF" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
您在构建UI时遇到了一些问题。这里有一个修复程序,请确保
@drawable/logo
文件位于drawable文件夹中
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/logo"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:orientation="horizontal" />
<ImageView
android:id="@+id/logo"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginBottom="10dp"
android:background="@drawable/logo"
app:layout_constraintBottom_toTopOf="@+id/name"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout" />
<TextView
android:id="@+id/name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:background="#FFF"
android:textColor="#000"
android:textSize="33sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/textView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/logo" />
<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="207dp"
android:background="#FFF"
android:textColor="#000"
android:textSize="33sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/name" />
如果项目尚未生成,预览可能为空或出错。但如果已经生成,则快速修复程序正在重建或清理项目…^请尝试上述方法,如果不起作用,请转到
文件>使缓存无效/重新启动@Xenolion谢谢您的回答。我尝试过重建、清理、使缓存失效和重新启动,但没有一个解决方案真正起作用。“有什么想法吗?”MohammedAlSafwan也尝试过,但没有成功。我可以尝试其他解决方案吗?您的布局有视图吗???再次感谢。只是为了了解我写的布局中的错误,我自己仍然无法识别它们。还有,是否必须使用约束布局?它们不是错误,而是更多的逻辑结构问题。你有一个文本视图,它有wrap_content
,因为它是宽度,但没有内容,所以没有显示出来。您也有嵌套视图,没有理由在那里,所以我也为您修复了它。谢谢。如果我以后有任何问题,我将与您联系:)。