简体   繁体   English

在android studio的设计预览中,布局是空的

[英]Layouts are empty on design preview of android studio

I have been working on a project and one day my layouts are appear empty in design of android studio. 我一直在研究一个项目,有一天我的布局在android studio的设计中显得空洞。

I have already tried putting "Base." 我已经尝试过“Base”了。 before "Theme.AppCompat.Light.DarkActionBar" in file style.xml, I also tried cleaning project and invalidate caches/restart but nothing works. 在文件style.xml中的“Theme.AppCompat.Light.DarkActionBar”之前,我还尝试了清理项目并使缓存/重启无效,但没有任何效果。

I have this code in manifest.xml 我在manifest.xml中有这个代码

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

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon_vismec"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".Login.Activity_Login"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".Login.Activity_LoginServer"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity
            android:name=".Activity_Main"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity android:name=".Tasks.Activity_Tasks" />
        <activity android:name=".Tasks.Activity_Tasks_Client" />
        <activity android:name=".Tasks.Activity_Task_Corretiva" />
        <activity android:name=".Activity_Profile" />
        <activity
            android:name=".Activity_Notifications"
            android:theme="@style/AppTheme.NoActionBar" />
        <activity android:name=".Activity_Historic" />
        <activity android:name=".Activity_Calendar" />
        <activity android:name=".Tasks.Activity_Task_Preventiva" />
        <activity android:name=".Main2Activity"></activity>
    </application>

</manifest>

For the error NOTE: One or more layouts are missing the layout_width or layout_height attributes. These are required in most layouts. Or: Automatically add all missing attributes 对于错误NOTE: One or more layouts are missing the layout_width or layout_height attributes. These are required in most layouts. Or: Automatically add all missing attributes NOTE: One or more layouts are missing the layout_width or layout_height attributes. These are required in most layouts. Or: Automatically add all missing attributes

It means you missed some width or height in some views. 这意味着您在某些视图中错过了一些宽度或高度。

<ImageView
    android:id="@+id/imageView"
    android:layout_width="wrap_content" <<<< this
    android:layout_height="wrap_content" <<< and this
    android:src="@drawable/logo_splashscreen"
    android:scaleType="fitCenter"/>

You can look into your layout.xml and see if every View has these 2 attributes. 您可以查看layout.xml并查看每个View是否具有这两个属性。 Or if any of them been set to 0 ? 或者,如果它们中的任何一个被设置为0

If that's the reason. 如果那就是原因。 In the latest version of AndroidStudio, You might see some hints like this 在最新版本的AndroidStudio中,您可能会看到一些类似的提示 在此输入图像描述

You mentioned the whole View is blank, I might check the root view of that activity.xml or you can consider paste the xml here. 您提到整个View是空白的,我可能会检查该activity.xml的根视图,或者您可以考虑在此处粘贴xml

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

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