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

时间:2013-04-30 12:14:30

标签: 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_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"/>

在上面的代码一侧给了我空间:)把我的其他东西放在屏幕上。

4 个答案:

答案 0 :(得分:2)

<?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:background="@android:color/black"
    android:orientation="vertical"
    android:weightSum="3" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:weightSum="3" >

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

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

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

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="horizontal" >

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

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

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

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:weightSum="3" >

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

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

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

</LinearLayout>

我已经改变了图像的来源,我认为你可以修改它。

答案 1 :(得分:2)

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

答案 2 :(得分:0)

答案 3 :(得分:0)

像这样使用。这将完全符合您的要求。

<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>
相关问题