2013-05-15 22 views
0

我跑到一個小問題,我想創建定位在圖像的某個部分的按鈕。Android Xml編程,取決於大小的可用空間上的按鈕

我的原始雖然是使用圖像作爲我的LinearLayout的背景,並將按鈕放置在地圖的頂部。我可以通過更改邊距來按照我想要的方式放置它們,但是當屏幕尺寸發生變化時,我遇到了問題。

的源代碼:

<LinearLayout android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:layout_width="fill_parent"> 

<LinearLayout 
    android:layout_width="300dp" 
    android:layout_height="300dp" 
    android:background="@drawable/howlingabyssmap" 
    android:orientation="horizontal" > 
    <ImageButton 
     android:id="@+id/imageButton2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginRight="120dp" 
     android:layout_marginTop="180dp" 
     android:background="@drawable/health" 
     android:src="@drawable/health"/> 

</LinearLayout> 

難道現在的人的方式來解決這個問題?我嘗試使用weightSum和layout_weight,但我沒有設法解決它。

回答

0

在FrameLayout中使用按鈕和ImageView而不是使用LinearLayout和ImageButton

+0

它沒有用。只要屏幕大小發生變化,按鈕就會跳轉。即使屏幕尺寸發生變化,我也希望它保持在圖像中的相同位置 –

相關問題