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

查看:121
本文介绍了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的文本"选项卡,组件树"中甚至在运行模式下看到拖放的所有元素,但在设计选项卡中看不到,在设计视图中什么也没有显示,并且即使是您好世界也总是空白在上面.

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.

我尝试了Invalidate Cache Restart(重启缓存无效),重新启动PC,更改Zoom(缩放)-放大和缩小,推断出约束条件,但是都没有运气.控件

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

推荐答案

好,我的问题解决了!

以下类无法实例化:-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天全站免登陆