2

我有这个结构main layout

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
tools:context="com.pingvalue.example.MainActivity">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true"
    android:theme="@style/AppTheme.AppBarOverlay">

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/toolbar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <include
            android:id="@+id/linear_header"
            layout="@layout/product_detail_header" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

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

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


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


<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


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

这是我在内部片段中使用的布局ViewPager

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:padding="6dp">

    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:drawableRight="@drawable/ic_insert_emoticon_black_24px"
        android:gravity="center_vertical"
        android:hint="@string/what_do_you_want_to_say"
        android:textSize="16sp" />

    <Button
        android:layout_width="40dp"
        android:layout_height="30dp"
        android:layout_marginLeft="6dp"
        android:background="@drawable/ic_send_selector"
        android:enabled="false" />

</LinearLayout>

</LinearLayout>

我想实现以下行为。这是AppBarLayout折叠时的屏幕截图:

在此处输入图像描述

如您所见,带有EditTextand的布局Button是可见的,但是当我向上滚动时它会消失。我尝试了自定义CoordinatorLayout行为,但它不起作用,因为它不是我的CoordinatorLayout. 我也尝试过更改match_parent为,wrap_content但它在LinearLayout.

在此处输入图像描述

4

3 回答 3

1

将带有 EditText 的 LinearLayout 放在 CoordinatorLayout 之外,并将所有内容包装在 LinearLayout 中。

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.pingvalue.example.MainActivity">

    <android.support.design.widget.CoordinatorLayout 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight=1>

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <include
                android:id="@+id/linear_header"
                layout="@layout/product_detail_header" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/AppTheme.PopupOverlay" />

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

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


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

    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>


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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="6dp">

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:drawableRight="@drawable/ic_insert_emoticon_black_24px"
            android:gravity="center_vertical"
            android:hint="@string/what_do_you_want_to_say"
            android:textSize="16sp" />

        <Button
            android:layout_width="40dp"
            android:layout_height="30dp"
            android:layout_marginLeft="6dp"
            android:background="@drawable/ic_send_selector"
            android:enabled="false" />

    </LinearLayout>

</LinearLayout>

这应该允许您让您的作曲家区域始终可见,无论您滚动标题多远。

于 2017-04-21T17:02:20.687 回答
0

我也试过添加一个没有结果的 NestedScrollView

于 2016-09-26T07:53:01.093 回答
0

尝试以下布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="6dp"
        android:layout_weight="0">

        <EditText
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:drawableRight="@drawable/ic_insert_emoticon_black_24px"
            android:gravity="center_vertical"
            android:hint="@string/what_do_you_want_to_say"
            android:textSize="16sp" />

        <Button
            android:layout_width="40dp"
            android:layout_height="30dp"
            android:layout_marginLeft="6dp"
            android:background="@drawable/ic_send_selector"
            android:enabled="false" />

    </LinearLayout>

</LinearLayout>
于 2016-09-25T09:33:51.213 回答