【问题标题】:Stack ImageButtons on top and side by side to each other将 ImageButtons 彼此并排堆叠在一起
【发布时间】:2015-04-28 22:30:25
【问题描述】:

我有以下 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 的网格,所以这就是我想要的,两个图像按行。现在发生的是逐行“无限”图像,尽管我只能看到两个,因为其他的被添加到屏幕外。如何在布局中避免这种情况?

【问题讨论】:

    标签: android


    【解决方案1】:

    尝试将布局更改为:

    <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>
    

    【讨论】:

    • omfg,太棒了... tysm
    猜你喜欢
    • 2021-03-20
    • 1970-01-01
    • 2021-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多