Android 向ScrollView添加片段似乎缺少一些layoutParams
我试图向ScrollView添加片段,但找不到一种方法来指定有效的布局参数 片段是这样创建的:Android 向ScrollView添加片段似乎缺少一些layoutParams,android,android-fragments,scrollview,Android,Android Fragments,Scrollview,我试图向ScrollView添加片段,但找不到一种方法来指定有效的布局参数 片段是这样创建的: FragmentManager supportFragmentManager = getActivity().getSupportFragmentManager(); SomeFragment fragment = new SomeFragment(); FragmentTransaction fragmentTransaction = supportFragmentManager.beginTra
FragmentManager supportFragmentManager = getActivity().getSupportFragmentManager();
SomeFragment fragment = new SomeFragment();
FragmentTransaction fragmentTransaction = supportFragmentManager.beginTransaction();
fragmentTransaction.add(R.id.scrollView, fragment).commit();
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="25dp">
</RelativeLayout>
这是滚动视图:
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="25dp"
android:scrollbars="none"
android:background="#0000FF">
我通过将RelativeLayout中的一个子视图高度从Match_Parent更改为25dp来修复它。虽然有点奇怪,但它是有效的
看起来,当像这样添加片段时,默认的布局参数是Wrap\u content,我仍然想知道是否有办法改变它。Write-android:layout\u height=match\u在相对布局中的父项最初是这样的,但这也不起作用。
ScrollView.LayoutParams params = new ScrollView.LayoutParams(ScrollView.LayoutParams.MATCH_PARENT, ScrollView.LayoutParams.MATCH_PARENT);
fragment.getView().setLayoutParams(params);