【发布时间】:2017-06-21 14:10:52
【问题描述】:
我有许多页面,其内容大于屏幕,即用户必须向下滚动才能看到更多内容。这些页面位于 ViewPager 中。对于我的生活,我无法弄清楚如何使垂直滚动工作。
为了清楚起见,我不想垂直翻页到另一个页面,只需在单个页面内向下滚动即可。
我希望有人能指出我正确的方向。搜索不会产生任何结果,但如果这不是常见的事情,我会感到惊讶吗?
我尝试过的:
- 围绕包含视图分页器和其他视图的线性布局包裹滚动视图。
- 布局和布局参数的不同组合。
谢谢
根据建议,我从 AndroidHive 中获取了示例,所以我的片段 xml 在下面,它有足够的内容,它不适合屏幕。所以我希望能够像列表视图一样向下滚动以查看其余内容。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="info.androidhive.materialtabs.fragments.OneFragment">
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/one"
android:textSize="40dp"
android:textStyle="bold" />
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:text="@string/one"
android:textSize="40dp"
android:textStyle="bold" />
<TextView
android:id="@+id/text2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text1"
android:text="@string/one"
android:textSize="40dp"
android:textStyle="bold" />
<TextView
android:id="@+id/text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text2"
android:text="@string/one"
android:textSize="40dp"
android:textStyle="bold" />
<TextView
android:id="@+id/text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text3"
android:text="@string/one"
android:textSize="40dp"
android:textStyle="bold" />
<TextView
android:id="@+id/text5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text4"
android:text="@string/one"
android:textSize="40dp"
android:textStyle="bold" />
<TextView
android:id="@+id/text6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text5"
android:text="@string/one"
android:textSize="40dp"
android:textStyle="bold" />
<TextView
android:id="@+id/text7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text6"
android:text="@string/one"
android:textSize="40dp"
android:textStyle="bold" />
<TextView
android:id="@+id/text8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text7"
android:text="@string/one"
android:textSize="40dp"
android:textStyle="bold" />
<TextView
android:id="@+id/text9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text8"
android:text="@string/one"
android:textSize="40dp"
android:textStyle="bold" />
<TextView
android:id="@+id/text10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/text9"
android:text="@string/one"
android:textSize="40dp"
android:textStyle="bold" />
</RelativeLayout>
</ScrollView>
我没有更改示例代码中的任何其他内容。
【问题讨论】:
-
您的 Scrollview 标签未关闭。
-
抱歉复制不正确,其实是正确关闭的
-
相对布局相对于彼此排列视图组。您可以将文本排列在另一个文本视图的左侧 在您的示例中,一个简单的解决方案是使用线性布局。因此,每个文本视图都排列在彼此的底部 [阅读更多] (androidexample.com/Relative_Layout_Basics_-_Android_Example/…)
标签: android android-layout android-viewpager