2016-12-08 9 views
0

私は、フラグメントレイアウトでこのコードを使用しています:LinearLayoutをScrollViewで正しく配置する方法は?

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

    <android.support.v4.widget.NestedScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:fitsSystemWindows="true" 
     android:scrollbars="vertical" 
     android:scrollbarAlwaysDrawVerticalTrack="true" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:background="@color/colorDivider"> 
     <android.support.v7.widget.RecyclerView 
      android:id="@+id/list" 
      android:layout_width="match_parent" 
      android:layout_height="500dp" 
      android:scrollbars="vertical" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" 
      /> 
    </LinearLayout> 
    </android.support.v4.widget.NestedScrollView> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_margin="10dp" 
     android:layout_alignParentBottom="true" 
     android:weightSum="2" 
     > 

     <EditText 
      android:id="@+id/edit_text" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1.91" 
      android:layout_marginLeft="10dp" 
      android:textColor="@color/colorPrimaryDark" 
      android:textColorHint="@color/colorPrimaryDark" 
      android:theme="@style/btmedtext" 
      android:textColorHighlight="@color/colorPrimary" 
      android:hint="Send message" 
      android:inputType="textMultiLine" 
      android:maxLines="6" 
      android:scrollbars="vertical"> 
     </EditText> 

     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/button_send" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_marginRight="3dp" 
      android:layout_marginLeft="10dp" 
      android:layout_marginBottom="16dp" 
      android:layout_gravity="bottom|end" 
      android:src="@drawable/ic_mic_white_24dp"/> 

    </LinearLayout> 

</RelativeLayout> 

結果は次のとおりです。

enter image description here

私の質問は次のとおりです。Recyclerview上でこの浮きのLinearLayout(のEditText + FloatingActionButton)を回避する方法? このLinearLayoutを一番下にしておきたいのですが、EditTextを使用すると、ScrollViewが上に移動します。フローティング操作ボタンを使用して

enter image description here

+0

試すかlayout_below = @ id/list –

+0

残念ながら、これは動作しません。ビューは互いに表示することはできません – GB11

答えて

0

残念なことにとき、それはあなたの唯一の選択肢は、完全にボタンを移動し、ボタンを非表示にされているか、あなたは、このようにブロックされたコンテンツを移動し、動的に最後に空の容器を追加することができそうですアップ。

THISライブラリを確認してください。動いているか空のコンテナが質問から外れているなら、これを利用することができます。それはあなたのボタンを保持し、必要なときにそれを提示することができます。

Floating Action Button Hide Library

+0

ありがとう、私はこのライブラリを表示します。ちなみに、私のアップデートをチェックしてWhatsAppチャットの写真を見てください。それはまさに私が必要なものです。 – GB11

0

が、私はこれがあなたの問題解決を願っています

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


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:background="@color/colorDivider"> 
     <android.support.v7.widget.RecyclerView 
      android:id="@+id/list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scrollbars="vertical" 
      android:layout_above="@+id/editbox_laypou" 
      app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:layout_alignParentBottom="true" 
      android:weightSum="2" 
      android:id="@+id/editbox_laypou"> 

      <EditText 
       android:id="@+id/edit_text" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1.91" 
       android:layout_marginLeft="10dp" 
       android:textColor="@color/colorPrimaryDark" 
       android:textColorHint="@color/colorPrimaryDark" 
       android:textColorHighlight="@color/colorPrimary" 
       android:hint="Send message" 
       android:inputType="textMultiLine" 
       android:maxLines="6" 
       android:scrollbars="vertical"> 
      </EditText> 

      <android.support.design.widget.FloatingActionButton 
       android:id="@+id/button_send" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_alignParentRight="true" 
       android:layout_marginRight="3dp" 
       android:layout_marginLeft="10dp" 
       android:layout_marginBottom="16dp" 
       android:layout_gravity="bottom|end" 
       android:src="@drawable/ic_mic_white_24dp"/> 

     </LinearLayout> 
    </RelativeLayout> 

0

でこれを追加しalign_parentBottom = "true" を追加し、あなたのマニフェスト

android:windowSoftInputMode="adjustPan" 
関連する問題