【发布时间】:2016-01-26 07:53:38
【问题描述】:
我想知道是否有任何方法可以让 ScrollView 中的孩子一次只显示 2 个孩子。我尝试让每个孩子的布局高度 = 0dp 并设置权重,但它会一次显示所有孩子。 我已经尝试将孩子的身高设置为特定的数量,但它只适用于我的特定屏幕尺寸。
这是我的示例代码:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:clickable="false"
android:focusableInTouchMode="false"
android:focusable="false">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#ff0000"
android:layout_weight=".5"></LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#7458ff"
android:layout_weight=".5"></LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#56ffe3"
android:layout_weight=".5"></LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#ffffff"
android:layout_weight=".5"></LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#fffd69"
android:layout_weight=".5"></LinearLayout>
</LinearLayout>
Here is what it looks like when I set the view height to 0dp and use weights
【问题讨论】:
-
你想为第一个和第二个线性布局做这个吗?或者每次你进入这个布局时,滚动后你只需要在那个屏幕上有两个布局?@Potato
标签: java android scrollview children