Android Studio渲染异常:"LinearLayout的mBaselineAlignedChildIndex指向不知道如何获取其基线的视图"

won*_*ana 5 xml android android-studio

Android Studio中此设计视图错误的原因是什么?

渲染期间引发异常:mBaselineAlignedChildIndex of LinearLayout points to a View that doesn't know how to get its baseline.

这是布局:

    <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>
Run Code Online (Sandbox Code Playgroud)

Man*_*saW 0

刚刚遇到了同样的错误。基线对齐与父 LinearLayout 相关,确定每个子项的基线,特别是布局中最后一个子项的基线。我的问题涉及 TimePicker - 在 API 21+ 中,它是一个图形时钟,因此没有 TextView 来提供基线信息。

这里,问题出现在第 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"                             
Run Code Online (Sandbox Code Playgroud)

您在按钮周围的内部 LinearLayout 上缺少“android:orientation=vertical”(或水平),并且Button 本身指定了“bottom”的父级(“线性重力”)内的重力。没有为其指定任何方向或高度,因此外部 LinearLayout 不知道如何确定它的基线。

另外,内部 LinearLayout 本身是不必要的。如果您希望列表和按钮之间有一个空白空间,请尝试使用空间小部件,或者如果您希望列表一直填充到按钮的空间,请为列表指定权重属性(“layout-weight=1.0”) )。