渲染问题 注意: 一个或多个布局缺少layout_width或layout_height属性。在大多数布局中这些是必需的。

11

我正在进行一个Android项目,一切都正常,但昨天打开项目后一直出现以下错误:

渲染问题
提示:一个或多个布局缺少layout_width或layout_height属性。这在大多数布局中是必需的。
在"visibility"属性中"invisible"不是有效的整数(有109个相似的错误未显示)
提示:尝试刷新布局。

即使我开始一个新项目并进入布局,仍然会出现该错误。

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:background="@color/backgroundDark"
    tools:context="coalesce.collabup.LoginActivity">

    <!-- Login progress -->
    <ProgressBar
        android:id="@+id/login_progress"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:visibility="gone" />

    <ScrollView
        android:id="@+id/login_form"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/email_login_form"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/Logo"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:text="CollabUp"
                android:textSize="70sp"
                android:lineSpacingExtra="8sp"
                android:typeface="normal"
                android:textAlignment="center"
                android:textStyle="normal|bold" />
            <TextView
                android:id="@+id/motto"
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:text="Collaboration at its finest"
                android:textStyle="normal|bold"
                android:textAlignment="center"
                android:layout_marginTop="20dp"
                android:layout_marginBottom="50dp" />

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <AutoCompleteTextView
                    android:id="@+id/email"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Email"
                    android:inputType="textEmailAddress"
                    android:maxLines="1"
                    android:singleLine="true"
                    android:textSize="18sp"
                    android:padding="10dp"
                    android:layout_marginBottom="10dp" />

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
               >

                <EditText
                    android:id="@+id/password"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Password"
                    android:imeActionId="@+id/login"
                    android:imeActionLabel="Sign In"
                    android:imeOptions="actionUnspecified"
                    android:inputType="textPassword"
                    android:maxLines="1"
                    android:singleLine="true" />

            </android.support.design.widget.TextInputLayout>
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
            <CheckBox
                android:text="keep me log in?"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/checkBox2"
                android:layout_marginTop="10dp" />

            <Button
                android:id="@+id/email_sign_in_button"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="16dp"
                android:text="Sign In"
                android:textStyle="bold"
                android:layout_marginLeft="250dp"
                android:layout_marginBottom="10dp"

                />
</RelativeLayout>
            <TextView
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:id="@+id/registertxt"
                android:text="New to CollabUp? Create an Account now!"
                android:textStyle="normal|bold"
                android:textAlignment="center"
                android:textSize="14sp"
                android:onClick="gotoRegister"
                android:layout_marginBottom="20dp" />

            <TextView
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:id="@+id/forgettxt"
                android:text="Forgot your password?"
                android:textStyle="normal|bold"
                android:textAlignment="center"
                android:onClick="gotoSendForget"
                android:textSize="14sp" />
            <TextView
                android:layout_height="match_parent"
                android:layout_width="match_parent"
                android:id="@+id/creditstxt"
                android:text="Coalesce 2016 - All rights Reserved - CollabUp"
                android:textStyle="normal|bold"
                android:textColor="@android:color/white"
                android:textAlignment="center"
                android:textSize="14sp"
                android:layout_marginTop="20dp" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

日志和 XML 代码,请 :) - MohammedAlSafwan
错误可能不在代码中。一个或多个布局缺少属性,或者属性设置错误。 - OneCricketeer
需要粘贴您的 XML 代码。 - Dhaval Solanki
我不知道是不是XML的问题,但是即使我启动一个新项目,我还是会遇到这个错误。 - rbcastro17
6个回答

28
问题已通过以下更改解决:
  1. 关闭 Android Studio

  2. 转到 C:\Users\UserName.android 并将 build-cache 文件夹重命名为 buildcache.bak

  3. 转到 C:\Users\UserName.AndroidStudio3.2\system 并重命名以下文件夹:

    (1) 将 caches 重命名为 caches.bak
    (2) 将 compiler 重命名为 compiler.bak
    (3) 将 compile-server 重命名为 compile-server.bak
    (4) 将 conversion 重命名为 conversion.bak
    (5) 将 external_build_system 重命名为 external_build_system.bak
    (6) 将 frameworks 重命名为 frameworks.bak
    (7) 将 gradle 重命名为 gradle.bak
    (8) 将 resource_folder_cache 重命名为 resource_folder_cache.bak

重新打开 Android Studio 并再次打开您的项目。


有时候安卓应用开发真的很痛苦!!谢谢你的答案兄弟 :) 它帮了我很多。 - Darshn
1
对我来说没用。他们只是创建了同名的新文件夹而已。错误仍然存在。 - David Dimalanta
感谢Gaurav Singhal,这是解决此问题的完美答案。 - Prince Dholakiya
为什么更改这些文件夹名称可以解决问题?还有其他的替代方案吗? - pecific_rim
1
同样的错误。在MacOS上有解决方案吗? - Dalai_Lama
对于Linux用户,文件夹位于Home文件夹下的.cache/Google/AndroidStudio2021.1中(请确保打开“显示隐藏文件”)。 - Reejesh

9

这个问题出现在新版本的Android Studio 3.2中,你可以通过删除缓存文件来解决该错误。 步骤1:关闭Android Studio。 步骤2:进入.AndroidStudio3.2->system->caches。 步骤3:删除所有文件。 步骤4:重新打开Android Studio。


1
运行得非常好。其他答案对我没有用。谢谢。 - Gordon developer

0

0

我使用了Clean Project(Build -> Clean Project)的简单功能,不知何故它对我有用!


0

我也遇到了这个错误。以下是帮助我的方法:

删除 Android Studio 文件

为了删除任何 Android Studio 设置文件的残留,在文件资源管理器中,进入你的用户文件夹(%USERPROFILE%),并删除 .android, .AndroidStudio 以及任何类似的带有版本号结尾的目录,例如 .AndroidStudio1.2,还有如果存在的话,.gradle.m2

源代码 在这里

但我没有删除这些文件夹。我只是删除了文件夹名称中的点。之后,我启动了 Android Studio。她建议我从旧文件夹中导出设置(在其中我删除了标题中的点)。我拒绝了并重新调整了工作室。之后我打开了项目,一切正常。 对于我的英语表示抱歉。我希望你能理解我的回答 :)


0
你的模板出问题了。只需要打开文件菜单然后选择设置。在顶部搜索框中搜索模板并找到文件和代码模板。选择它,然后选择右侧的其他选项卡。点击Android,再点击layoutResourcesFile.xml。 将下面的代码复制粘贴进去,并确保你点击了实时模板。
<?xml version="1.0" encoding="utf-8"?>
<${ROOT_TAG} xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="${LAYOUT_WIDTH}"
             android:layout_height="${LAYOUT_HEIGHT}">

</${ROOT_TAG}>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接