0

我正在尝试创建一个 Horizo​​ntalScrollView,它恰好是屏幕宽度的 3 倍。我尝试了以下代码,但滚动视图不会滚动。我该如何设置它,以便主 LinearLayout 内的 3 个 LinearLayouts 每个都是屏幕的宽度?

<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"

            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">

<!-- the container for all the pages -->
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal">

   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="100dp"
       android:background="#000000"/>

    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:background="#FF0000"/>
    <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="100dp"
            android:background="#FF0000"/>
</LinearLayout>

请注意,如果我给 LinearLayouts 一个特定的宽度,则滚动视图会滚动,但我需要每个 LinearLayout 都具有屏幕的宽度。

4

1 回答 1

0

您将需要在顶部 LinearLayout 上使用 wrap_content,并以编程方式设置子 LinearLayouts 的宽度。

于 2013-07-30T15:56:20.250 回答