2016-07-25 3 views
0

내 응용 프로그램에서 하나의 MainActivity 마녀에는 조각 용 컨테이너, CordinatoirLayout + RecycleView 및 CollapsingToolbarLayout이있는 CoordinatorFragment 및 하나의 TextView가있는 두 번째 SimpleFragment가 있습니다. 나는 모든 괜찮 먼저 초기화 후 CoordinatorLayout CollapsingToolbarLayout, RecyclerView 및 Fragments와 함께 발행

@Override 
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { 
     holder.itemView.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       getFragmentManager().beginTransaction().replace(R.id.fragmentContainer, new SimpleFragment()).addToBackStack("TAG").commit(); 
      } 
     }); 
    } 

먼저 조각을 대체 RecycleeView의 어댑터를 사용하여

<android.support.design.widget.CoordinatorLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/main_appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#FFF" 
     android:fitsSystemWindows="true"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/main.collapsing" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#0000" 
      android:fitsSystemWindows="true" 
      app:layout_scrollFlags="snap|scroll|enterAlways"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:background="#0000" 
       android:fitsSystemWindows="true" 
       android:orientation="vertical" 
       app:layout_collapseMode="none"> 

       <ImageView 
        android:id="@+id/first" 
        android:layout_width="wrap_content" 
        android:layout_height="23dp" 
        android:layout_marginLeft="20dp" 
        android:layout_marginRight="20dp" 
        android:layout_marginTop="30dp" 
        android:adjustViewBounds="true" /> 

       <TextView 
        android:id="@+id/second" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="20dp" 
        android:layout_marginRight="20dp" 
        android:layout_marginTop="40dp" /> 

       <TextView 
        android:id="@+id/third" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="20dp" 
        android:layout_marginRight="20dp" /> 

       <View 
        android:layout_width="match_parent" 
        android:layout_height="130dp" 
        android:layout_marginTop="20dp" 
        android:background="#fff" /> 
      </LinearLayout> 
     </android.support.design.widget.CollapsingToolbarLayout> 

     <View 
      android:id="@+id/fourth" 
      android:layout_width="match_parent" 
      android:layout_height="10dp" 
      android:background="#fff" 
      app:layout_collapseMode="pin" /> 

     <LinearLayout 
      android:id="@+id/fiveth_field" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:background="@color/colorPrimary" 
      app:layout_collapseMode="pin"> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="center_horizontal" 
       android:padding="20dp" 
       android:text="RIGHT" /> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="center_horizontal" 
       android:padding="20dp" 
       android:text="LEFT" /> 
     </LinearLayout> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior" /> 
</android.support.design.widget.CoordinatorLayout> 

: MainActivity를 만들에 나는 첫번째 조각을

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    FragmentTransaction transaction = getFragmentManager().beginTransaction(); 
    Fragment fragment = new CoordinatorFragment(); 
    transaction.replace(R.id.fragmentContainer,fragment); 
    transaction.commit(); 
} 

CoordinatorFragnet의 레이아웃을 추가 할 수 있습니다. RecyclerView 내용과 마지막 항목을 완전히 볼 수 있습니다.

Scroll to last (first init)

그러나 두 번째 단편으로 이동하고 다시 첫번째 조각에 이동 버튼을 다시 클릭 한 후 RecyclerView의 마지막 항목이 도구 모음의 일부를 축소하지의 크기에 cutted된다. 이 항목을 완전히 볼 수있는 기능이 없습니다. 다른 모든 기능은 Ok입니다.

Scroll to last (after fragments replacement and click back button)

모든 아이디어를 어떻게 조각 기반 구현을 떠나이 문제를 해결하는 방법? 미리 감사드립니다 !!

답변

0

RecyclerView의 높이를 match_parent으로 변경하십시오.

+0

불행히도 –

+0

은 'fitsSystemWindows'와 관련된 문제 일 수 있습니다. 시도 할 수있는 것들 : CoordinatorLayout 속성에서 true로 추가하고, 액티비티의 기본 레이아웃 및 두 번째 조각의 레이아웃에서 true인지 확인하고 두 조각의 루트보기에서'setFitsSystemWindows (true) '를 호출하십시오. – GPack

+0

또는 FrameLayout을 [여기] (http://stackoverflow.com/a/34345286/4274296)로 교체하십시오. – GPack

0

일부 시도 후에 코디네이터 프래그먼트의 레이아웃을 리팩터링하기로 결정했습니다. 마지막 요소는 "LEFT"와 "RIGHT"TextViews를 사용하여 LinearLayout 높이에서 정확하게 자르기 때문에 AppBarLayout에서 제거하고 RecyclerView 위의 RelativeLayout에 추가합니다. 이 문제가 해결되었습니다. 리팩토링 후

CoordinatorFragment의 레이아웃 :

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 

    <android.support.design.widget.AppBarLayout 
     android:id="@+id/main_appbar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="#FFF"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:id="@+id/main.collapsing" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#0000" 
      app:layout_scrollFlags="snap|scroll|enterAlways"> 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="200dp" 
       android:background="#0000" 
       android:orientation="vertical" 
       app:layout_collapseMode="none"></LinearLayout> 
     </android.support.design.widget.CollapsingToolbarLayout> 
    </android.support.design.widget.AppBarLayout> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

     <LinearLayout 
      android:id="@+id/fiveth_field" 
      android:layout_width="match_parent" 
      android:layout_height="60dp" 
      android:background="@color/colorPrimary" 
      android:orientation="horizontal"> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="center_horizontal" 
       android:padding="20dp" 
       android:text="RIGHT" /> 

      <TextView 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_weight="1" 
       android:gravity="center_horizontal" 
       android:padding="20dp" 
       android:text="LEFT" /> 
     </LinearLayout> 

     <android.support.v7.widget.RecyclerView 
      android:id="@+id/recyclerView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@+id/fiveth_field" /> 
    </RelativeLayout> 
</android.support.design.widget.CoordinatorLayout> 

나는이 CoordinatorLayout + AppBarLayout 구현에 문제가 있다고 생각합니다. 어쩌면 내 anwser 누군가에게 유용 할 것입니다.

관련 문제