RelativeLayout - 将 Fragment 保持在底部
RelativeLayout - Keep Fragment at the bottom
这是我的代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/buttonsFragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:id="@+id/scrollViewer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/buttonsFragment1">
<LinearLayout
android:id="@+id/showSomething"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical" />
</ScrollView>
<FrameLayout
android:id="@+id/buttonsFragment2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/scrollViewer" />
</RelativeLayout>
最后一个 FrameLayout 包含一个带有一些按钮的 Fragment。此 FrameLayout 应保留在屏幕底部。但是使用此代码,片段 buttonsFragment2
不会显示在我的智能手机上。
我只看到顶部的 buttonsFragment1
,我可以向下滚动 LinearLayout,但在底部,没有 buttonsFragment2
。怎么了?
编辑:我的片段class:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.myFragment, container, false);
Fragment topFrag = new TopFragment();
Fragment bottomFrag = new BottomFragment();
FragmentTransaction top = getChildFragmentManager().beginTransaction();
top.add(R.id.topFragment, topFragment).commit();
FragmentTransaction bottom = getChildFragmentManager().beginTransaction();
bottom.add(R.id.bottomFragment, bottomFragment).commit();
return view;
}
如果我正确理解了您的布局,这就是您正在寻找的解决方案。滚动视图填充片段之间的屏幕:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/buttonsFragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:id="@+id/scrollViewer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/buttonsFragment2"
android:layout_below="@+id/buttonsFragment1">
<LinearLayout
android:id="@+id/showSomething"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical" />
</ScrollView>
<FrameLayout
android:id="@+id/buttonsFragment2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
这是我的代码:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/buttonsFragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:id="@+id/scrollViewer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/buttonsFragment1">
<LinearLayout
android:id="@+id/showSomething"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical" />
</ScrollView>
<FrameLayout
android:id="@+id/buttonsFragment2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@+id/scrollViewer" />
</RelativeLayout>
最后一个 FrameLayout 包含一个带有一些按钮的 Fragment。此 FrameLayout 应保留在屏幕底部。但是使用此代码,片段 buttonsFragment2
不会显示在我的智能手机上。
我只看到顶部的 buttonsFragment1
,我可以向下滚动 LinearLayout,但在底部,没有 buttonsFragment2
。怎么了?
编辑:我的片段class:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.myFragment, container, false);
Fragment topFrag = new TopFragment();
Fragment bottomFrag = new BottomFragment();
FragmentTransaction top = getChildFragmentManager().beginTransaction();
top.add(R.id.topFragment, topFragment).commit();
FragmentTransaction bottom = getChildFragmentManager().beginTransaction();
bottom.add(R.id.bottomFragment, bottomFragment).commit();
return view;
}
如果我正确理解了您的布局,这就是您正在寻找的解决方案。滚动视图填充片段之间的屏幕:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/buttonsFragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ScrollView
android:id="@+id/scrollViewer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/buttonsFragment2"
android:layout_below="@+id/buttonsFragment1">
<LinearLayout
android:id="@+id/showSomething"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical" />
</ScrollView>
<FrameLayout
android:id="@+id/buttonsFragment2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>