我正在尝试将协调器布局与应用栏布局一起使用,该布局将 fragment 托管为“ ScrollView ”。该 fragment 由一个 recyclerView 和一个底部对齐的布局组成,其中包含一个按钮,如下所示:
但是,底部部分默认隐藏:
并且仅在我滚动后显示。
来 self 的 Activity 课:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TestFragment fragment = (TestFragment) getFragmentManager().findFragmentByTag("Test");
if (fragment == null)
fragment = new TestFragment();
getFragmentManager().popBackStack();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.fragment_container, fragment, "Test");
fragmentTransaction.commit();
}
Activity 布局:
<RelativeLayout 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.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="enterAlways|scroll"
app:tabGravity="fill"
app:tabMode="fixed"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>
fragment 布局:
<RelativeLayout 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.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/bottomView"
android:scrollbars="vertical"
android:visibility="visible"/>
<RelativeLayout
android:id="@+id/bottomView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#d4285d"
app:layout_scrollFlags="enterAlways">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do something..."
android:textSize="14sp"/>
</RelativeLayout>
</RelativeLayout>
这里的最终目标是让 fragment 的底部栏始终在屏幕上,并且回收器 View 将应用栏滚动开。
这可能吗?
谢谢大家!
最佳答案
目前看来这不可能(永远?)。
关于android - 如何使用 fragment 为 "scrolling view"的协调器布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31709100/