【问题标题】:CoordinatorLayout not working properly with 2 child layoutsCoordinatorLayout 不能与 2 个子布局一起正常工作
【发布时间】:2016-04-16 22:14:15
【问题描述】:

我在根有一个 CoordinatorLayout,它的 AppBarLayout 包含一个具有 2 个 LinearLayout 作为子级的 LinearLayout。我们将这些子布局称为 A 和 B。我不能同时显示 A 和 B 的内容。 A 显示和 B 的内容不显示,当我删除 A 的内容时,B 的内容才显示,反之亦然。这就是我在 LinearLayout 容器中同时包含 A 和 B 的内容时的样子。

A 和 B 都有 Textviews 但只有 A 的 TextView 显示而 B 没有。

这是布局的代码:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar">
        <LinearLayout
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ffff"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
            <LinearLayout
                android:orientation="vertical"
                android:minWidth="25px"
                android:minHeight="25px"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/A"
                android:padding="10dp">
                <TextView
                    android:text="Large Text"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/title"
                    android:textColor="#000000"
                    android:fontFamily="sans-serif-light" />
            </LinearLayout>
            <LinearLayout
                android:orientation="horizontal"
                android:minWidth="25px"
                android:minHeight="25px"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/B"
                android:background="@drawable/border"
                android:padding="10dp">
                <TextView
                    android:text="Large Text"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/textview"
                    android:textColor="#000000"
                    android:fontFamily="sans-serif-light" />
            </LinearLayout>
        </LinearLayout>
    </android.support.design.widget.AppBarLayout>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>

我已经尝试了所有方法,但我无法弄清楚哪里出了问题。滚动行为很好,但我看不到 A 和 B 的内容。 有人可以帮忙吗?

【问题讨论】:

    标签: android scroll android-coordinatorlayout


    【解决方案1】:

    我通过使用 FrameLayout 而不是 Linearlayout 作为 A 和 B 的容器解决了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-07-05
      • 1970-01-01
      • 2017-01-18
      • 2018-11-10
      • 2014-07-01
      • 1970-01-01
      • 2016-07-19
      相关资源
      最近更新 更多