简体   繁体   English

Android工作室预览不显示布局

[英]Android studio preview does not show layouts

I have just started to learn android studio. 我刚刚开始学习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. 但是,如果我更改主题或在模拟器中运行应用程序,它们会出现,但它们会重叠。

For API 27: 对于API 27:

Add the following dependency: If you are using targetSdkVersion 27, in your App Level gradle file build.gradle(Module: app) 添加以下依赖项:如果您使用的是targetSdkVersion 27,请在App Level gradle文件build.gradle(Module:app)中

implementation 'com.android.support:appcompat-v7:27.1.1' 实现'com.android.support:appcompat-v7:27.1.1'

For API 28: 对于API 28:

if you are using targetSdkVersion 28, 如果您使用的是targetSdkVersion 28,

Step 1: Make sure you have the following dependency: 第1步:确保您具有以下依赖项:

implementation 'com.android.support:appcompat-v7:28.0.0-rc02' 实现'com.android.support:appcompat-v7:28.0.0-rc02'

UPDATE: For the latest appcompat-v7 library repo version, follow this link 更新:有关最新的appcompat-v7库存回购版本,请点击此链接

https://mvnrepository.com/artifact/com.android.support/appcompat-v7?repo=google https://mvnrepository.com/artifact/com.android.support/appcompat-v7?repo=google

Step 2: 第2步:

Goto Values > styles.xml and modify the style as follows, 转到Values> styles.xml并修改样式如下,

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM