2015-04-28 83 views
0

我有以下的ImageButton格式:堆栈ImageButtons彼此

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

imagebuttons被添加,但只有并排,并最终继续被添加到屏幕外。图像按钮的指定空间可用于2x2x2x2x2的网格,所以这就是我想要的,每行两个图像。现在发生的事情是按行排列的“无限”图像,尽管我只能看到两个图像,因为其他图像会被添加到屏幕外。我怎样才能在布局中避免这种情况?

回答

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

OMFG,惊艳... tysm – Fane