Android ScrollView中的片段太小
简短问题:我想让滚动视图中的片段占据所有可用空间。我怎样才能做到这一点 详细信息:我有一个片段,我把它放在父布局的滚动视图中。该滚动视图占据了父布局中的大部分空间。尽管如此,片段在滚动视图中看起来非常小。图中说明了这一点: 这是片段的XML:Android ScrollView中的片段太小,android,android-layout,android-fragments,Android,Android Layout,Android Fragments,简短问题:我想让滚动视图中的片段占据所有可用空间。我怎样才能做到这一点 详细信息:我有一个片段,我把它放在父布局的滚动视图中。该滚动视图占据了父布局中的大部分空间。尽管如此,片段在滚动视图中看起来非常小。图中说明了这一点: 这是片段的XML: <?xml version="1.0" encoding="utf-8"?> <GridView xmlns:android="http://schemas.android.com/apk/res/android" android
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ImagePickerGridView" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:gravity="center" android:stretchMode="columnWidth"
android:numColumns="auto_fit" android:horizontalSpacing="5dp"
android:verticalSpacing="5dp" android:background="@color/orange1">
</GridView>
试试这个:
<ScrollView android:layout_width="fill_parent"
android:id="@+id/imagePickerScrollView" android:layout_weight="1.0"
android:layout_height="fill_parent" android:background="@color/orange1" android:layout_gravity="fill_vertical">
</ScrollView>
…正如@nik所说,还添加了安卓:fillViewport=true好的,我发现了问题所在。事实证明GridView是一个可滚动的容器,所以不需要将它放在ScrollView中。一旦我将网格视图放入线性布局中,一切都正常了!我仍然不知道为什么GridView会在ScrollView中收缩,可能是因为本来就不应该在那里:
谢谢大家的回答 不,它不起作用。。。然而,我想我找到了答案。我没有意识到GridView本身是一个可滚动的容器!我会在一分钟内发布解决方案。谢谢谢谢事实证明,问题在于将GridView放在ScrollView中。我在另一个答复中解释了这一点。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image_picker_1);
Log.d(CLASS_NAME, "onCreate");
m_multiPicSelect = getIntent().getBooleanExtra(IntentHelper.MULTI_SELECT, false);
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
Fragment fragment = new ImagePickerFragment();
fragmentTransaction.add(R.id.imagePickerScrollView, fragment);
fragmentTransaction.commit();
}
<ScrollView android:layout_width="fill_parent"
android:id="@+id/imagePickerScrollView" android:layout_weight="1.0"
android:layout_height="fill_parent" android:background="@color/orange1" android:layout_gravity="fill_vertical">
</ScrollView>