17

CoordinatorLayoutの中にCollapsingToolBarを使用しています。子ビューとしてEditTextを含むNestScrollViewがあります。私が直面しているのは、edittextに焦点が当てられ、keybaoardが完全なビューがスクロールしないように見える場合です。EditTextがフォーカスを取得したときにCollapsingToolbarLayoutが崩壊しない

以下はそのレイアウトの出力としてのコードとイメージです。

<android.support.design.widget.AppBarLayout 
    android:id="@+id/appbar" 
    android:layout_width="match_parent" 
    android:layout_height="@dimen/app_bar_height" 
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> 

    <android.support.design.widget.CollapsingToolbarLayout 
     android:id="@+id/collapsing_toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:expandedTitleMarginEnd="64dp" 
     app:expandedTitleMarginStart="48dp" 
     app:contentScrim="?attr/colorPrimary" 
     app:layout_scrollFlags="scroll|exitUntilCollapsed"> 


     <ImageView 
      android:id="@+id/ivProductImage" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop" 
      android:src="@drawable/stub_image" 
      app:layout_collapseParallaxMultiplier="0.7" 
      app:layout_collapseMode="parallax" /> 

     <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/ThemeOverlay.AppCompat.Light" /> 

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

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

<android.support.v4.widget.NestedScrollView 
    android:id="@+id/nested_scroll_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    <LinearLayout 
     android:id="@+id/containerLayout" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp" 
      android:layout_marginTop="10dp"> 

      <EditText 
       android:id="@+id/etProductTitle" 
       style="@style/EditTextStyle" 
       android:hint="@string/lbl_product_title" 
       android:inputType="text" 
       android:textSize="24dp" /> 
     </android.support.design.widget.TextInputLayout> 

     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp"> 

      <EditText 
       android:id="@+id/etProductDescription" 
       style="@style/EditTextStyle" 
       android:hint="@string/lbl_description" 
       android:inputType="text" /> 
     </android.support.design.widget.TextInputLayout> 

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

      <android.support.design.widget.TextInputLayout 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:layout_weight="0.5"> 

       <EditText 
        android:id="@+id/etDeposit" 
        style="@style/EditTextStyle" 
        android:hint="@string/lbl_deposit" 
        android:inputType="number" /> 
      </android.support.design.widget.TextInputLayout> 

      <android.support.design.widget.TextInputLayout 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:layout_weight="0.5"> 

       <EditText 
        android:id="@+id/etPricePerDay" 
        style="@style/EditTextStyle" 
        android:hint="@string/lbl_price_per_day" 
        android:inputType="number" /> 
      </android.support.design.widget.TextInputLayout> 
     </LinearLayout> 

     <android.support.design.widget.TextInputLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="10dp" 
      android:layout_marginRight="10dp"> 

      <EditText 
       android:id="@+id/etLocation" 
       style="@style/EditTextStyle" 
       android:hint="@string/lbl_add_location" 
       android:inputType="text" /> 
     </android.support.design.widget.TextInputLayout> 

     <TextView 
      style="@style/SubHeading" 
      android:layout_margin="10dp" 
      android:text="@string/lbl_categories" 
      android:textColor="@color/color_primary" /> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recyclerView" 
      android:layout_width="match_parent" 
      android:layout_height="315dp" 
      android:layout_marginLeft="10dp" 
      android:isScrollContainer="false" 
      android:layout_marginRight="10dp" 
      android:scrollbars="none" /> 

    </LinearLayout> 
</android.support.v4.widget.NestedScrollView> 

enter image description here

+0

あると思いますか? – streamride

+0

私はRecyclerViewを削除して 'NestedScrollView'の中で' RecyclerView'を使っていました。私の問題を解決しました。 –

答えて

2

RecyclerView。、これらのスクロール可能なウィジェットがお互いに動作しないことを意味し、スクロール可能なウィジェットです(ただし、RecyclerViewNestedScrollingChildからの子である)

詳細については、この質問を確認してください:

How to use RecyclerView inside NestedScrollView?

しかし、あなたはカスタムところでLinearLayoutManager

https://stackoverflow.com/a/32736113/4409113


でそれを使用することができ、

あなたは0を使用することができますCoordinatorLayoutの内側とNestedScrollViewの外側の

希望に役立ちます。

1

私はEditTextOnFocusChangeListenerを追加することによって、それが集中した場合は、これを解決した - ちょうどsetExpandedメソッドでビューを折りたたむ:あなたがしたい場合は、あなたのCollapsingToolbarLayoutときに、他のEditText年代から毎回崩壊すること

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
    @Override 
    public void onFocusChange(final View v, boolean hasFocus) { 
     if (hasFocus) { 
      mAppBarLayout.setExpanded(false, true); 
     } 
    } 
}); 

あなたのレイアウトに焦点が当てられたら、それぞれに同じOnFocusChangeListenerを設定する必要があります。

+2

これは最善の解決策のようですが、 'mAppBarLayout.setExpanded(false)'を使って 'CollapsingToolbarLayout'を崩壊させる方が簡単です。 – TR4Android

+0

'setExpanded'メソッドを使わなかったのは、このメソッドがv23バージョンのデザインライブラリにしか現れなかったからですが、私は以前に実装しました。 – rom4ek

0

私はあなたがそれを解決しましたこんにちは、私は、同じ問題を持っているすべての研究の後に、これが最善の解決策

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
@Override 
public void onFocusChange(final View v, boolean hasFocus) { 
    if (hasFocus) { 
     mAppBarLayout.setExpanded(false, true); // second one for animation 
    } 
} 
}); 
関連する問題