Android studio 预览不显示布局 [英] Android studio preview does not show layouts

查看:104
本文介绍了Android studio 预览不显示布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习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(Module: app)

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 步:确保您有以下依赖项:

实现'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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆