Android Studio渲染异常:“mbaselinealign nedchildindex of LinearLayout指向一个不知道如何获取基线的视图”

时间:2021-11-12 20:49:43

What the cause of this design view error in Android Studio?

Android Studio出现这种设计视图错误的原因是什么?

Exception raised during rendering: mBaselineAlignedChildIndex of LinearLayout points to a View that doesn't know how to get its baseline.

渲染过程中出现的异常:线性布局的mbaselinealign nedchildindex指向一个不知道如何获取基线的视图。

Here's the layout:

这里的布局:

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

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

            <ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/bg_btn_btm_actionbar"
                android:src="@mipmap/ab_solid_example"/>

            <ListView
                android:id="@+id/eventStates"
                android:layout_width="wrap_content"
                android:layout_height="40dp"
                android:background="@drawable/listviewimg"
                android:drawSelectorOnTop="true"
                android:footerDividersEnabled="true"
                android:headerDividersEnabled="true"
                android:textColor="#000000" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <Button
                    android:id="@+id/btn_cancel_callresult"
                    android:layout_width="153dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"                             android:layout_marginRight="@dimen/abc_action_bar_default_padding_material"
                    android:background="@color/white"
                    android:onClick="cancelCallResult"
                    android:text="Cancel"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textColor="@color/white" />



            </LinearLayout>
        </LinearLayout>
    </ScrollView>

</LinearLayout>

2 个解决方案

#1


0  

Just had this same error. Baseline-alignment has to do with the parent LinearLayout determining the baseline of each child, and specifically, the last child in the layout. My issue involved a TimePicker - in API 21+, it's a graphical clock, so there are no TextViews to provide baseline information.

只是有同样的错误。基线对齐与父线性布局有关,它确定每个子布局的基线,特别是布局中的最后一个子布局。我的问题涉及一个时间选择器——在API 21+中,它是一个图形时钟,所以没有textview来提供基线信息。

Here, the problem is in lines 27-35:

问题在第27-35行:

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/btn_cancel_callresult"
            android:layout_width="153dp"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"                             

You're missing an "android:orientation=vertical" (or horizontal) on this inner LinearLayout around the Button, and the Button itself specifies a gravity within its parent ("linear-gravity") of "bottom". There's no orientation or height specified for any of it, so the outer LinearLayout doesn't know how to determine a baseline for it.

在这个按钮周围的内部线性布局中,你会漏掉一个“android:orientation=vertical”(或horizontal),而按钮本身指定了“bottom”的父元素(“linear-gravity”)中的重力。没有为它指定方向或高度,因此外部线性布局不知道如何为它确定基线。

Also, that inner LinearLayout is unnecessary as-is. If you want an empty space between the List and the Button, try using a Space widget, or if you want the List to fill the space all the way to the Button, give the List a weight attribute ("layout-weight=1.0").

同样,内部线性布局也是不必要的。如果您想要列表和按钮之间的空白,请尝试使用空格小部件,或者如果您想要列表一直填到按钮,请给列表一个权重属性(“layout-weight=1.0”)。

#2


0  

I know this is old but for people who run into this problem, this is a known bug, lookup "Issue 214062". It has been resolved in API 24.

我知道这是旧的,但是对于遇到这个问题的人来说,这是一个已知的bug,查找“问题214062”。它已经在API 24中得到了解决。

It is only a problem on the Android Studio preview tab, not on the actual emulator or device, when TimePicker visibility is gone. To fix this issue, use tools namespace as quickfix, so that at least you'll be able to see the preview, while still being hidden on a device, like so:

这只是Android Studio preview选项卡上的一个问题,而不是实际的模拟器或设备上的问题,因为时间选择器的可见性已经消失。要解决这个问题,请使用tools名称空间作为quickfix,这样至少您可以看到预览,同时仍然隐藏在设备上,如下所示:

<TimePicker
        android:id="@+id/timerpicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        tools:visibility="visible"
        />

#1


0  

Just had this same error. Baseline-alignment has to do with the parent LinearLayout determining the baseline of each child, and specifically, the last child in the layout. My issue involved a TimePicker - in API 21+, it's a graphical clock, so there are no TextViews to provide baseline information.

只是有同样的错误。基线对齐与父线性布局有关,它确定每个子布局的基线,特别是布局中的最后一个子布局。我的问题涉及一个时间选择器——在API 21+中,它是一个图形时钟,所以没有textview来提供基线信息。

Here, the problem is in lines 27-35:

问题在第27-35行:

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <Button
            android:id="@+id/btn_cancel_callresult"
            android:layout_width="153dp"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"                             

You're missing an "android:orientation=vertical" (or horizontal) on this inner LinearLayout around the Button, and the Button itself specifies a gravity within its parent ("linear-gravity") of "bottom". There's no orientation or height specified for any of it, so the outer LinearLayout doesn't know how to determine a baseline for it.

在这个按钮周围的内部线性布局中,你会漏掉一个“android:orientation=vertical”(或horizontal),而按钮本身指定了“bottom”的父元素(“linear-gravity”)中的重力。没有为它指定方向或高度,因此外部线性布局不知道如何为它确定基线。

Also, that inner LinearLayout is unnecessary as-is. If you want an empty space between the List and the Button, try using a Space widget, or if you want the List to fill the space all the way to the Button, give the List a weight attribute ("layout-weight=1.0").

同样,内部线性布局也是不必要的。如果您想要列表和按钮之间的空白,请尝试使用空格小部件,或者如果您想要列表一直填到按钮,请给列表一个权重属性(“layout-weight=1.0”)。

#2


0  

I know this is old but for people who run into this problem, this is a known bug, lookup "Issue 214062". It has been resolved in API 24.

我知道这是旧的,但是对于遇到这个问题的人来说,这是一个已知的bug,查找“问题214062”。它已经在API 24中得到了解决。

It is only a problem on the Android Studio preview tab, not on the actual emulator or device, when TimePicker visibility is gone. To fix this issue, use tools namespace as quickfix, so that at least you'll be able to see the preview, while still being hidden on a device, like so:

这只是Android Studio preview选项卡上的一个问题,而不是实际的模拟器或设备上的问题,因为时间选择器的可见性已经消失。要解决这个问题,请使用tools名称空间作为quickfix,这样至少您可以看到预览,同时仍然隐藏在设备上,如下所示:

<TimePicker
        android:id="@+id/timerpicker"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:visibility="gone"
        tools:visibility="visible"
        />