Android Studio预览不显示布局 [英] Android studio preview does not show layouts
问题描述
我刚刚开始学习android studio.我遇到了一个问题:
I have just started to learn android studio. I've encountered a problem:
添加布局后,布局不会显示在预览中.但是,如果我更改主题或在模拟器中运行应用程序,它们确实会出现但它们会重叠.
The layouts won't appear in the preview after I have added them. But if I change the theme or run the app in the emulator they do appear but they overlap.
推荐答案
对于API 27:
添加以下依赖项: 如果您使用的是targetSdkVersion 27, 在您的应用程序级别gradle文件中 build.gradle(模块:应用程序)
Add the following dependency: If you are using targetSdkVersion 27, in your App Level gradle file build.gradle(Module: app)
实现'com.android.support:appcompat-v7:27.1.1'
对于API 28:
如果您使用的是targetSdkVersion 28,
if you are using targetSdkVersion 28,
第1步: 确保您具有以下依赖性:
Step 1: Make sure you have the following dependency:
实现'com.android.support:appcompat-v7:28.0.0-rc02'
更新:有关最新的appcompat-v7库回购版本,请单击此链接
UPDATE: For the latest appcompat-v7 library repo version, follow this link
https://mvnrepository.com/artifact/com .android.support/appcompat-v7?repo = google
第2步:
转到值> styles.xml并按如下所示修改样式,
Goto Values > styles.xml and modify the style as follows,
<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
或您喜欢的任何其他基本主题.
or any other base theme you like.
这是为您提供的示例约束布局,
Here is an example constraint layout for you,
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<EditText
android:id="@+id/enter_age"
android:layout_width="200dp"
android:layout_height="100dp"
android:ems="10"
android:hint="enter age"
android:inputType="number"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/button1"
app:layout_constraintVertical_chainStyle="packed" />
<Button
android:id="@+id/button1"
android:layout_width="200dp"
android:layout_height="110dp"
android:onClick="butGetAge"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/enter_age"
app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>
这篇关于Android Studio预览不显示布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!