堆叠ImageButtons在顶部并排放置到彼此

时间:2015-04-28 14:16:11

标签: android

我有以下 ImageButton 格式:

<ImageButton
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    style="?android:attr/buttonStyleSmall"
    android:text="New Button"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:scaleType="fitXY"
    android:layout_alignParentTop="true"/>

这是容器布局(注意id)

       <ScrollView
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_below="@+id/textView"
            android:layout_marginTop="5dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true">

            <RelativeLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

                <GridLayout
                    android:orientation="horizontal"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
      ---->         android:id="@+id/ADDING IMGBUTTONS HERE"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true">

                </GridLayout>

                <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_below="@id/ADDING IMGBUTTONS HERE"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true"></LinearLayout>

            </RelativeLayout>
        </ScrollView>

图像按钮被添加,但只是并排,最终继续在屏幕上添加。图像按钮的指定空间可用于2x2x2x2x2的网格,这样就是什么我想要,两个图像的行。现在发生的事情是&#34;无限&#34;按行排列,虽然我只能看到两个,因为其他人在屏幕外添加。我怎样才能在布局中避免这种情况?

1 个答案:

答案 0 :(得分:0)

尝试将布局更改为:

<GridLayout
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:columnCount="2"  
    android:rowCount="2">    

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView1"
        android:layout_row="0"      
        android:layout_column="0"   
        android:background="@mipmap/ic_launcher" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView2"
        android:layout_row="0"         
        android:layout_column="1"      
        android:background="@mipmap/ic_launcher" />
</GridLayout>
相关问题