Android 缩放图像以相对布局填充屏幕

Android 缩放图像以相对布局填充屏幕,android,android-layout,Android,Android Layout,我对Android的布局非常陌生。你们能帮我缩放图片以覆盖空白的宽度和高度吗 这是屏幕 它都向右边倾斜。我怎样才能让它填满屏幕 这是布局图 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_

我对Android的布局非常陌生。你们能帮我缩放图片以覆盖空白的宽度和高度吗

这是屏幕

它都向右边倾斜。我怎样才能让它填满屏幕

这是布局图

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

    >

      <RelativeLayout
          android:id="@+id/jkmenu1"
          android:layout_width="match_parent"
          android:layout_height="match_parent" >

          <ImageButton
              android:id="@+id/atm"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignBottom="@+id/airport"
              android:layout_alignLeft="@+id/birthday"
              android:background="@android:color/transparent"
              android:src="@drawable/atm" />

          <ImageButton
              android:id="@+id/currency"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignLeft="@+id/birthday"
              android:layout_alignTop="@+id/classifieds"
              android:src="@drawable/currency"
              android:background="@android:color/transparent" />

          <ImageButton
              android:id="@+id/education"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentRight="true"
              android:layout_below="@+id/coffee"
              android:background="@android:color/transparent"
              android:src="@drawable/education" />

          <ImageButton
              android:id="@+id/coffee"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentRight="true"
              android:layout_below="@+id/bar"
              android:background="@android:color/transparent"
              android:src="@drawable/coffee" />

          <ImageButton
              android:id="@+id/bar"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_above="@+id/birthday"
              android:layout_alignParentRight="true"
              android:background="@android:color/transparent"
              android:src="@drawable/bar" />

          <ImageButton
              android:id="@+id/birthday"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_below="@+id/atm"
              android:layout_toLeftOf="@+id/coffee"
              android:background="@android:color/transparent"
              android:src="@drawable/bithday" />

          <ImageButton
              android:id="@+id/beauty"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_centerVertical="true"
              android:layout_toLeftOf="@+id/atm"
              android:background="@android:color/transparent"
              android:src="@drawable/beauty" />

          <ImageButton
              android:id="@+id/airport"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_above="@+id/beauty"
              android:layout_alignLeft="@+id/beauty"
              android:background="@android:color/transparent"
              android:src="@drawable/airport" />

          <ImageButton
              android:id="@+id/classifieds"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignLeft="@+id/beauty"
              android:layout_alignTop="@+id/education"
              android:background="@android:color/transparent"
              android:src="@drawable/classifieds" />

      </RelativeLayout>

</LinearLayout>

谢谢大家

添加空间的解决方案是

我补充说

<View android:layout_height="60sp"/>

在上面的代码端,它给了我空间:)将我的其他东西放在屏幕上。

考虑使用或

网络上有很多例子,请查看:



考虑使用或

网络上有很多例子,请查看:




我已经更改了图像的来源,我想您可以修改它。


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/jkmenu1"
    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/atm"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" >
        </ImageButton>
        <ImageButton
            android:id="@+id/currency"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
        <ImageButton
            android:id="@+id/education"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal" >
        <ImageButton
            android:id="@+id/coffee"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
        <ImageButton
            android:id="@+id/bar"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
        <ImageButton
            android:id="@+id/birthday"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal" >
        <ImageButton
            android:id="@+id/beauty"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
        <ImageButton
            android:id="@+id/airport"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
        <ImageButton
            android:id="@+id/classifieds"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>
</LinearLayout>
我已经更改了图像的来源,我想您可以修改它。


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/jkmenu1"
    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/atm"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" >
        </ImageButton>
        <ImageButton
            android:id="@+id/currency"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
        <ImageButton
            android:id="@+id/education"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal" >
        <ImageButton
            android:id="@+id/coffee"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
        <ImageButton
            android:id="@+id/bar"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
        <ImageButton
            android:id="@+id/birthday"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="horizontal" >
        <ImageButton
            android:id="@+id/beauty"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
        <ImageButton
            android:id="@+id/airport"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
        <ImageButton
            android:id="@+id/classifieds"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@android:color/transparent"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>
</LinearLayout>

像这样使用。这将完全满足您的需求

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:stretchColumns="*" >

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />
    </TableRow>

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />
    </TableRow>

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />
    </TableRow>

</TableLayout>

像这样使用。这将完全满足您的需求

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:stretchColumns="*" >

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />
    </TableRow>

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />
    </TableRow>

    <TableRow
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_weight="1" >

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:src="@drawable/ic_launcher" />
    </TableRow>

</TableLayout>



如果你想适合每个屏幕,你可以使用带权重的线性布局或使用表格布局。你可以给我看一些例子@sankarvi如果你想适合每个屏幕,你可以使用带权重的线性布局或使用表格布局。你可以给我看一些链接的例子@sankarvtanks。我将通读这些文章,但您是否有快速的想法使其暂时生效,而不是使用相对线布局,使用3个水平线布局,每行一个。然后,将android:layout_weight=“1”添加到每个ImageButton。空间将被满足,所有的都将有相同的宽度,但它们可能不是完全正方形,它们将有一个矩形,它们都有相同的尺寸。感谢链接。我将通读这些文章,但您是否有快速的想法使其暂时生效,而不是使用相对线布局,使用3个水平线布局,每行一个。然后,将android:layout_weight=“1”添加到每个ImageButton。空间会被填满,所有的都会有相同的宽度,但它们可能不是完全正方形,它们会有一个矩形,所有图片的尺寸都相同。谢谢@Triode我更改了图片的来源,但是随着你的布局,每个图片都分散了,而不是来源。你能为图片按钮设置背景吗?然后它就可以工作了:)谢谢它工作了,但是我如何为页脚和上面的图片留出空间呢?你可以为第一个图片设置边距线性布局和最后的布局。谢谢@Triode我更改了图像源,但是随着您的布局,每个图像都分散而不是源,您可以将图像按钮的背景设置为图像,然后它就会工作:)谢谢它工作了,但是我如何为页脚和上面的图像留出空间?您可以为首先是线性布局,也是最后一个布局。非常感谢,但现在图像是如何连接它们并填充区域将图像设置为背景而不是源。当设置为背景时,使用9个补丁图像,因为图像将被拉伸。感谢它拉伸,但我如何限制内部内容不覆盖页脚空间。它也分布在页脚空间。对不起,内部内容不覆盖页脚空间?我不清楚这个说法。你能把图像显示得更清楚些吗?这是屏幕。我怎样才能在上面的图片后面留下小空间,在页脚的空间里,图片也会扩散到所有的侧面。我想要页脚的空间和页眉下面的小空间了。我怎样才能离开呢?非常感谢,但是现在这些图片都是我如何加入它们并填充区域呢?将图片设置为背景而不是源。当设置为背景时,使用9个补丁图像,因为图像将被拉伸。感谢它拉伸,但我如何限制内部内容不覆盖页脚空间。它也分布在页脚空间。对不起,内部内容不覆盖页脚空间?我不清楚这个说法。你能把图像显示得更清楚些吗?这是屏幕。我怎样才能在上面的图片后面留下小空间,在页脚的空间里,图片也会扩散到所有的侧面。我想要页脚的空间和页眉下面的小空间了。我怎么走that@Homan它在某种程度上起到了作用,但是图像离我很远,我怎样才能加入并填满屏幕呢。在ImageButton中所有图像的大小都相同,请将android:layout\u width=“wrap\u content”更改为android:layout\u width=“match\u parent”,并将android:scaleType=“fitXY”添加到it@Homan它在某种程度上起到了作用,但是图像离我很远,我怎样才能加入并填满屏幕呢。所有图像在ImageButton中大小相同,将android:layout\u width=“wrap\u content”更改为android:layout\u width=“match\u parent”,并将android:scaleType=“fitXY”添加到其中