Android Studio 3.1.3,设计视图始终为空 [英] Android Studio 3.1.3, design view is always empty

查看:30
本文介绍了Android Studio 3.1.3,设计视图始终为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Android 开发的新手,我的 Android Studio 3.1.3 演示项目或我创建的任何项目都遇到了这个问题.

I'm new to android development and I have this problem with my Android Studio 3.1.3 demo project or any project that I create.

即使我可以在我的设计视图 (ConstraintLayout) 上拖放不同的控件但在设计视图上没有显示任何内容,它也会显示一秒钟然后消失.

Even though that I can drag and drop different controls on my design view (ConstraintLayout) but nothing shows on the design view, it shows for a split sec and then it disappears.

我可以在activity_main.xml文本选项卡、组件树甚至运行模式中看到我拖放的所有元素,但在设计选项卡中看不到,在设计视图中没有任何显示,它始终是空白的,甚至没有hello world显示在上面.

I can see all the elements which I drag and drop in activity_main.xml Text tab, Component Tree and even in run mode, but not in design tab, nothing shows in design view and it is always blank not even hello world shows on it.

我尝试了使缓存重启无效、重新启动我的电脑、更改缩放 - 放大和缩小、推断约束,但没有运气.控制

I tried Invalidate Cache Restart, Restarting my PC, changing Zoom - In and out, Inferring constraints, but no luck. Controls

除非在设计视图中查看事物,否则我无能为力.

I can't do much unless I see things in design view.

空设计视图:

运行模式视图

activity_main.xml

<?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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <Button
        android:id="@+id/button4"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:text="Button" />

    <android.support.constraint.Guideline
        android:id="@+id/guideline"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:layout_constraintGuide_begin="20dp" />

    <CheckBox
        android:id="@+id/checkBox"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="CheckBox"
        tools:layout_editor_absoluteX="154dp"
        tools:layout_editor_absoluteY="181dp" />

</android.support.constraint.ConstraintLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.libra.myapplication">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.libra.myapplication"
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

推荐答案

好的,我的问题解决了!

Ok my problem is solved!

以下类不能被实例化: - android.support.v7.widget.Toolbar

我从此更改了 res/values/styles.xml 文件:

I changed the res/values/styles.xml file from this:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">

为此:

<style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">

解决了这个问题

这篇关于Android Studio 3.1.3,设计视图始终为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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