Android布局 - 双水平滚动视图

时间:2011-12-22 15:49:29

标签: android-layout

是否有可能(一切皆有可能,对!)在一个布局屏幕上创建双水平滚动视图?

作为一个例子....我想要两个(或三个)行或图标独立滚动。我在像Pulse这样的应用上看到了这种行为。

请帮助布局代码......这是我的单身。滚动...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

        <HorizontalScrollView android:layout_height="100dp" >

            <ImageButton
                android:id="@+id/ImageButton1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/icon1" >
            </ImageButton>

            <ImageButton
                android:id="@+id/ImageButton2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/icon2" >
            </ImageButton>
        </HorizontalScrollView>

        <HorizontalScrollView android:layout_height="100dp" >

            <ImageButton
                android:id="@+id/ImageButton3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/icon3" >
            </ImageButton>

            <ImageButton
                android:id="@+id/ImageButton3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/icon4" >
            </ImageButton>
        </HorizontalScrollView>

    </LinearLayout>

** * *更新的代码仍无法正常工作......可能是高度/宽度属性?

2 个答案:

答案 0 :(得分:2)

这是解决方案,这是正常的

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <HorizontalScrollView 
        android:layout_height="100dp" 
        android:layout_width="100dp">
       <LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content">
        <ImageButton
            android:id="@+id/ImageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" >
        </ImageButton>

        <ImageButton
            android:id="@+id/ImageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" >
        </ImageButton>
       </LinearLayout>
    </HorizontalScrollView>

    <HorizontalScrollView android:layout_height="100dp"
        android:layout_width="100dp" >
       <LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content">

           <ImageButton
               android:id="@+id/ImageButton3"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:src="@drawable/ic_launcher" />

        <ImageButton
            android:id="@+id/ImageButton3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_launcher" >
        </ImageButton>
        </LinearLayout>
    </HorizontalScrollView>

</LinearLayout>

试试这个享受......

答案 1 :(得分:0)

只需将两个或多个滚动条放在一个LinearLayout

<LinearLayout
        android:orientation="vertical" ...>
    <HorizontalScrollView android:layout_height="100dp" .../>
    <HorizontalScrollView android:layout_height="100dp" .../>
    ...
</LinearLayout>