【发布时间】:2015-08-22 14:58:40
【问题描述】:
我使用了滚动视图,因为我的视图很长,我需要让用户向下滚动才能查看 TextViews 和 ImageViews 等项目。但是在底部,我需要一个 GridView 来显示无限的图像列表。
我需要能够滚动查看文本视图
和
我还需要能够到达 GridView 并滚动离开
但是,我意识到您不能在 Scrollview 中拥有 GridView,因为它们都涉及滚动,并且一些奇怪的错误使我无法滚动 GridView。我的情况有什么替代方案?
代码示例:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="30dp"
android:text="Hello there"
android:textColor="#CC000000"
android:textSize="25sp" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="30dp"
android:text="Partner Name: "
android:textColor="#CC000000"
android:textSize="25sp" />
<!-- Lot more TextViews -->
<!-- And then comes the GridView -->
<GridView
android:id="@+id/picturefeed"
android:numColumns="3"
android:layout_marginTop="20dp"
android:layout_below="@+id/partner_details"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</GridView>
</ScrollView>
【问题讨论】:
-
您的布局有错误,ScrollViews 只能有一个直接子级。
-
查看我的答案以获取示例代码。
标签: android android-layout android-activity gridview scrollview