java - Android Studio 3.0 布局编辑器/预览器
问题描述
我正在使用 Android Studio 3.0 制作一个 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 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" />
推荐阅读
- python - \1 (python) 的字符串替换
- python - Python - 在多个 for 循环之间未检测到 txt 文件
- azure - Azure App Service 使用服务总线队列消息,即使它已停止
- armadillo - 犰狳 + BLAS + LAPACK
- .net - 问:如何配置 cloudbuild.yaml 来运行测试?
- mysql - 如果输入为空,如何忽略枚举类型?
- php - 非法字符串偏移“名称”和未初始化的字符串偏移:0
- java - 如何从 StepExecutionListener 中的 beforeStep 方法中跳过步骤执行?
- c++ - 将基类的子类中的公共方法私有化
- c# - 服务远程处理/发送者 - 接收者