代码之家  ›  专栏  ›  技术社区  ›  Rajesh K

Android Studio 3.0布局编辑器/预览器

  •  1
  • Rajesh K  · 技术社区  · 7 年前

    我正在使用Android Studio 3.0制作Android应用程序。

    但我面临的问题是布局编辑器/预览器工作不正常。有时它什么也不显示,有时它会显示一个带有所有导航按钮的灰色框。

    这些是截图

    Screenshot 1

    Screenshot 2

    我用的是 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>
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   MohammedAlSafwan    7 年前

    您在构建UI时遇到了一些问题。这是一个解决方案,同时确保 @drawable/logo 文件位于 drawable folder

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