2013-04-30 114 views
0

我對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"/> 

在代碼上面給了我空間:)把我的其他東西放在屏幕上。

+2

如果u要適應每一個屏幕,你可以使用線性佈局,重量或使用TableLayout – 2013-04-30 12:21:36

+0

能否請你告訴我一些例子@SankarV – Yogus 2013-04-30 12:22:33

回答

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

非常感謝,但現在圖像是http://i.imgur.com/f5PWOST.png如何加入它們並填充區域 – Yogus 2013-04-30 12:53:26

+0

將圖像設置爲背景而不是源。當設置爲背景時,使用9個補丁圖像,因爲圖像會被拉伸。 – 2013-04-30 12:57:32

+0

感謝它拉伸,但我怎麼能限制內部內容不重寫頁腳空間。它也傳遍了頁腳空間。 – Yogus 2013-04-30 13:03:14

0

考慮使用TableLayoutGridLayout

有在網絡上許多例子,檢查這些了:

Android TableLayout Example
Android Sdk TableLayout
GridLayout in Android

+0

感謝您的鏈接。我將閱讀這些文章,但您是否有快速的想法讓它現在可以使用 – Yogus 2013-04-30 12:26:45

+0

而不是使用RelativeLayout,請使用3個水平LinearLayout,每行一個。然後,將android:layout_weight =「1」添加到每個ImageButton。空間將被滿足,它們都將具有相同的寬度,但它們可能不是完全正方形的,它們將具有矩形形狀,它們全都具有相同的尺寸。 – 2013-04-30 12:28:57

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> 

我變了,我認爲你可以修改它的圖片的來源。

+0

謝謝@Triode我改變了圖像源,但與您的佈局分散每個圖像http://i.imgur.com/EnxJwzq.png – Yogus 2013-04-30 12:39:46

+0

而不是源可以設置圖像按鈕的背景作爲您的圖像,然後它將工作: ) – Triode 2013-04-30 12:47:59

+0

感謝它的工作,但我怎麼能留下頁腳空間以及以上的圖像? – Yogus 2013-04-30 13:20:24

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

@霍曼它在一定程度上工作,但圖像是非常遙遠的,我怎麼可以加入然後填寫屏幕。所有圖片大小相同http://i.imgur.com/f5PWOST.png – Yogus 2013-04-30 12:54:17

+0

在ImageButton中,將android:layout_width =「wrap_content」更改爲android:layout_width =「match_parent」,並將android:scaleType =「fitXY」添加到它 – Homam 2013-05-01 11:22:04

相關問題