当前位置: 首页 > 知识库问答 >
问题:

Android Studio 3.1.3,设计视图始终为空

岑驰
2023-03-14

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

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

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

我试着让缓存重启无效,重启电脑,改变放大和缩小,推断出限制,但没有成功。控制

除非我从设计的角度看问题,否则我做不了什么。

空设计视图:

运行模式视图

主要活动。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'
}

共有3个答案

蓝逸仙
2023-03-14

我也遇到了同样的问题,发现这个黑客程序对我有效。我已经更改了Gradle脚本/构建中的应用程序文件中的版本。从gradle(模块:应用程序)升级到版本27CompileSdkVersionminSdkVersiontargetSdkVersionimplementation'com.Android支持:appcompat-v7:27.0.0'。这些列在第4、7、8和23行。。(对你来说可能不一样)。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.fiv4.masterapp"
        minSdkVersion 27
        targetSdkVersion 27
        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:27.0.0'
    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'
}
卫华奥
2023-03-14

另一个解决方法是编辑GradleScript/build。成绩(模块应用程序)

-

如果有,

-

  • 保存并同步
贺立果
2023-03-14

好了,我的问题解决了!

无法实例化以下类:-

我更改了分辨率/值/样式。来自以下位置的xml文件

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

为此:

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

这就解决了问题

 类似资料:
  • 我们已经完成了MVC中的C层,还有M和V没有做呢。这一小节来对视图进行设计,从后台到前台的渲染是这样的 后台给定一个视图位置,输出到前端JSP或者其他模板引擎上,做一个非常简单的接口: /** * 视图渲染接口 * @author biezhi * */ public interface Render { /** * 渲染到视图 * @param view

  • 有人能告诉我如何永远隐藏视图吗? 我用隐藏了一个视图,但是当重新打开应用程序时,我必须重新隐藏该视图。我想要一个视图隐藏总是当按钮被点击,直到清除应用程序数据或卸载。谢了!

  • 我正在创建一个应用程序,它包含3个活动,比如说,A,B和c。活动A是主活动,它在应用程序打开时启动。 使用startActivityForResult(intent,1)将活动A称为活动B;活动B返回一个成功捕获的结果,在活动a的onActivityResult中,我使用startActivityForResult(intent2,2)启动活动C; 这是我的活动A的onActivityResult

  • 我对@Cacheable和使用一个基于Spring表达式语言的自定义键有问题。我有以下代码 这将引发以下错误 我也尝试过静态方法。这将引发NullPointerException,因为providerDTO在此处为null。 我如何调试它来找出发生了什么?这是Spring 3.2.4版本。@cacheable标记在一个接口上,但我使用的是标准的spring AOP,而不是AspectJ,因此据我所

  • 下面是片段。请注意,我已经恢复到以前的提交,因此丢失了最近的修改,但请查看我编写的代码,然后才注意到始终等于0() 以下是当检测到活动后按: 以下是NoteActivity接收结果调用的方式。 null 我在我的项目上浪费了很多重要的时间,只是想知道是什么使resultCode和requestCode的值丢失了我发送的值。 任何帮助和指导都将不胜感激。非常感谢!

  • 我的数据库中有很多预定的帖子(location),我只想显示已经发布帖子的分类法(locationtype)。 因此,我创建了一个check\u term\u posts($term\u id)函数 但它总是返回0。 WP查询似乎是实现这一点的唯一方法,因为$term- $q-