2

我在main layout避免在里面ViewPager底视图滚动内CoordinatorLayout

<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处于折叠状态:

enter image description here

正如你可以看到与EditTextButton是可见的布局,但是当我向上滚动,它就会消失。我尝试了一个自定义的CoordinatorLayout行为,但它不起作用,因为它不是我的CoordinatorLayout的直接子女。我也尝试将match_parent更改为wrap_content,但它会在LinearLayout之下放置空白区域。

enter image description here

回答

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> 
+0

与图像中的行为相同 – aloj

0

我已经试过还加入了NestedScrollView没有结果

0

把LinearLayout中与您的EditText在它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> 

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

相关问题