Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/206.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 向ScrollView添加片段似乎缺少一些layoutParams_Android_Android Fragments_Scrollview - Fatal编程技术网

Android 向ScrollView添加片段似乎缺少一些layoutParams

Android 向ScrollView添加片段似乎缺少一些layoutParams,android,android-fragments,scrollview,Android,Android Fragments,Scrollview,我试图向ScrollView添加片段,但找不到一种方法来指定有效的布局参数 片段是这样创建的: FragmentManager supportFragmentManager = getActivity().getSupportFragmentManager(); SomeFragment fragment = new SomeFragment(); FragmentTransaction fragmentTransaction = supportFragmentManager.beginTra

我试图向ScrollView添加片段,但找不到一种方法来指定有效的布局参数

片段是这样创建的:

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);