В моем приложении у меня есть один объект MainActivity содержит контейнер для фрагментов, один фрагмент - координаторфрагмент с CordinatoirLayout + RecycleView и CollapsingToolbarLayout и второй - SimpleFragment с одним TextView. На создание MainActivity добавить первый фрагментКоординаторLayout в сочетании с CollapsingToolbarLayout, RecyclerView и Fragments issue
@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 в:
<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>
При использовании адаптера RecycleeView, я заменить первые фрагменты со вторым
@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();
}
});
}
После первой инициализации все Ok. Я могу прокрутить содержимое RecyclerView, а последний элемент полностью виден.
Но после переезда второго фрагмента и вернуться к первому фрагменту, нажав кнопку назад, последний элемент из RecyclerView является вырезанным по размеру не разрушится частью панели. И нет возможности полностью просмотреть этот предмет. Все остальные функции - Ок.
Scroll to last (after fragments replacement and click back button)
Любые идеи, как решить эту проблему, оставляя реализацию на основе фрагмента? Спасибо заранее!
К сожалению, это не помогло –
это может быть проблема, связанная с 'fitsSystemWindows'. Что вы можете попробовать: добавьте его как true в свойствах CoordinatorLayout, проверьте, истинно ли в главном макете действия и в макете второго фрагмента, вызовите 'setFitsSystemWindows (true)' в корневом представлении обоих фрагментов. – GPack
Или замените FrameLayout как [здесь] (http://stackoverflow.com/a/34345286/4274296) – GPack