android - 收到警告 : this linearlayout layout or its framelayout parent is possibly useless

标签 android warnings android-linearlayout android-framelayout

<TabHost
    android:id="@+id/tabHost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1" >

 // ---------------------------  Here I got warning  -------------------------
            <LinearLayout
                android:id="@+id/chat_list"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical"
                android:visibility="visible" >
 // --------------------------------------------------------------------------
                <ListView
                    android:id="@+id/listView"
                    android:layout_width="fill_parent"
                    android:layout_height="0dp"
                    android:layout_weight="1"
                    android:background="@color/white" >
                </ListView>

                <LinearLayout
                    android:id="@+id/text_entry"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:gravity="bottom"
                    android:orientation="horizontal" >

                    <EditText
                        android:id="@+id/txt_inputText"
                        android:layout_width="125dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.8"
                        android:hint="@string/enter_text"
                        android:inputType="text" />

                    <Button
                        android:id="@+id/btn_Send"
                        android:layout_width="100dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="0.2"
                        android:text="@string/send" />
                </LinearLayout>
            </LinearLayout>
        </FrameLayout>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0" >
        </TabWidget>
    </LinearLayout>
</TabHost>

如何解决这个警告?我找不到任何解决方案。任何帮助将不胜感激。

最佳答案

我不确定你到底想完成什么,但你可以通过移动 FrameLayout 来消除警告内容到一个单独的文件并将其添加回您的 TabHost通过使用 <include>标签。

一个可能的版本看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/tabHost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1">
            <include layout="@layout/tab_chat_list" />
        </FrameLayout>
    </LinearLayout>
</TabHost>

和 tab_chat_list.xml:

<?xml version="1.0" encoding="utf-8"?>
<merge  xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
        android:id="@+id/chat_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:visibility="visible" >

        <ListView
            android:id="@+id/listView"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:background="@color/white" >
        </ListView>

        <LinearLayout
            android:id="@+id/text_entry"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="bottom"
            android:orientation="horizontal" >

            <EditText
                android:id="@+id/txt_inputText"
                android:layout_width="125dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.8"
                android:hint="@string/enter_text"
                android:inputType="text" />

            <Button
                android:id="@+id/btn_Send"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:layout_weight="0.2"
                android:text="@string/send" />
        </LinearLayout>
    </LinearLayout>
</merge>

希望这对您有所帮助。

更新

我注意到有些人建议删除 FrameLayout .虽然,这可以解决其他情况下的问题,TabHost需求TabWidgetFrameLayout才能正常运行。

关于android - 收到警告 : this linearlayout layout or its framelayout parent is possibly useless,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18080316/

相关文章:

javascript - 升级到 React Native 0.55.4 后,isMounted() 警告不断出现

android - 如何使 Linearlayout 可滚动,两个 ListView 可滚动,包装其内容

android - 如何实现LinearLayout标题/标签

Android ScrollView 渲染 ImageView 非常慢

android - 如何在 RecyclerView 中设置自定义形状的 ImageButton 的背景?

Android 和 Retrofit2 - 在多部分请求中发布图像文件

perl - 启用全局警告

android - 使用 glColor 将纹理设置为半透明的问题

android - onCreateView : nullpointerexception后TextView为空

firebase - 警告 "It looks like you' 正在使用 Firebase JS SDK 的开发版本。”