Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何为图像按钮指定灵活的大小?_Android_Imagebutton - Fatal编程技术网

Android 如何为图像按钮指定灵活的大小?

Android 如何为图像按钮指定灵活的大小?,android,imagebutton,Android,Imagebutton,我想创建一个大小灵活的图像按钮,这样它们就可以毫无问题地安装在任何android设备中,这就是我使用的代码: <GridLayout android:id="@+id/grid1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_centerInParent="true" android

我想创建一个大小灵活的图像按钮,这样它们就可以毫无问题地安装在任何android设备中,这就是我使用的代码:

 <GridLayout
        android:id="@+id/grid1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_centerInParent="true"
        android:layout_marginTop="150dp"
        android:background="@drawable/corneres"
        android:columnCount="1"
        android:orientation="vertical" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/homeview"
            android:scaleType="centerInside"
            android:adjustViewBounds="true" />

        <ImageButton
            android:id="@+id/imageButton3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:layout_gravity="right|top"
            android:layout_row="0"
            android:src="@drawable/profiles"         
            android:scaleType="centerInside"
            android:adjustViewBounds="true"/>

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:layout_gravity="center"
            android:layout_row="0"
            android:src="@drawable/ac" 
            android:scaleType="centerInside"
            android:adjustViewBounds="true"/>

          .
          .
          .

    </GridLayout>

.
.
.

是我从某个设备获得的输出。将您的
网格布局
包装在
滚动视图中

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
     <GridLayout
         android:id="@+id/grid1"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:layout_centerInParent="true"
         android:layout_marginTop="150dp"
         android:background="@drawable/corneres"
         android:columnCount="1"
         android:orientation="vertical" >

         <ImageButton
             android:id="@+id/imageButton1"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:src="@drawable/homeview"
             android:scaleType="centerInside"
             android:adjustViewBounds="true" />  
         ....
         ....
         ....  
    </GridLayout>  
</ScrollView>  

....
....
....  
更新

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <ImageButton
             android:id="@+id/imageButton1"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
             android:src="@drawable/image"
             android:layout_weight="1"
             android:scaleType="centerInside"
             android:adjustViewBounds="true" />
        <ImageButton
             android:id="@+id/imageButton2"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
             android:src="@drawable/image"
             android:layout_weight="1"
             android:scaleType="centerInside"
             android:adjustViewBounds="true" />
        <ImageButton
             android:id="@+id/imageButton3"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
             android:src="@drawable/image"
             android:layout_weight="1"
             android:scaleType="centerInside"
             android:adjustViewBounds="true" />

    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <ImageButton
             android:id="@+id/imageButton4"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
             android:src="@drawable/image"
             android:layout_weight="1"
             android:scaleType="centerInside"
             android:adjustViewBounds="true" />
        <ImageButton
             android:id="@+id/imageButton5"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
             android:src="@drawable/image"
             android:layout_weight="1"
             android:scaleType="centerInside"
             android:adjustViewBounds="true" />
        <ImageButton
             android:id="@+id/imageButton6"
             android:layout_width="0dp"
             android:layout_height="wrap_content"
             android:src="@drawable/image"
             android:scaleType="centerInside"
             android:layout_weight="1"
             android:adjustViewBounds="true" />

    </LinearLayout>

</LinearLayout>


没有其他方法可以让它们只适合布局?尝试使用LinearLayout和
android:layout\u weight=“1”
android:layout\u height=“0dp”
对于所有
图像按钮
线性布局给了我一个非常奇怪的行为,只显示六个按钮中的两个,这一伟大的方式帮了我很多:)