2012-10-12 73 views
4

問題: 我似乎無法讓我的ImageButton出現在正確的位置或尺寸合適。ImageButtons Size and Placement not working in Eclipse

THE PLATFORM: 的Eclipse與Android API 16

問題: 我RelativeLayout的是600×800,我的ImageButtons是194x64,但是當我把他們在編輯器中,他們是兩倍大,因爲他們應該。看到鏈接到圖像。

enter image description here

我的XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:android1="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/main_portal_bg" > 

    <RelativeLayout 
     android1:layout_width="353dp" 
     android1:layout_height="758dp" 
     android1:layout_marginLeft="115dp" 
     android1:layout_marginTop="29dp" 
     android1:background="#000000" > 
    </RelativeLayout> 

    <ImageButton 
     android1:id="@+id/new_customer_button_selector" 
     android1:layout_width="194dp" 
     android1:layout_height="64dp" 
     android1:layout_marginTop="89dp" 
     android1:contentDescription="@string/back_button_desc" 
     android1:background="@drawable/new_customer_button_selector" /> 

    <ImageButton 
     android1:id="@+id/returning_customer_button_selector" 
     android1:layout_width="194dp" 
     android1:layout_height="64dp" 
     android1:layout_alignParentLeft="true" 
     android1:layout_below="@+id/new_customer_button_selector" 
     android1:contentDescription="@string/back_button_desc" 
     android1:src="@drawable/returning_customer_button_selector" /> 

    <ImageButton 
     android1:id="@+id/redeem_coupon_button_selector" 
     android1:layout_width="194dp" 
     android1:layout_height="64dp" 
     android1:layout_alignParentLeft="true" 
     android1:layout_below="@+id/returning_customer_button_selector" 
     android1:contentDescription="@string/back_button_desc" 
     android1:src="@drawable/redeem_coupon_button_selector" /> 

    <ImageButton 
     android1:id="@+id/info_button_selector" 
     android1:layout_width="194dp" 
     android1:layout_height="64dp" 
     android1:layout_alignParentLeft="true" 
     android1:layout_below="@+id/redeem_coupon_button_selector" 
     android1:contentDescription="@string/back_button_desc" 
     android1:src="@drawable/info_button_selector" /> 

</RelativeLayout> 

的研究: 我曾嘗試使用FitXY的ScaleType,設置MaxHeight和了minHeight,並採用了android:背景,而不是機器人的:SRC。我能夠縮小它們的唯一方法是使用圖形編輯器通過按住SHIFT並拖動右下角來調整它們的大小。這也不幸強制他們自動對齊佈局的底部,當我試圖移動它們時,他們回到他們的原始大小和所有其他按鈕洗牌周圍的佈局。編輯XML只會讓我成爲那裏的一部分。

問題: 每次我試圖在圖形編輯器中移動的按鈕,所有的其他按鈕獲得洗牌在屏幕上看似隨機的圖案。爲什麼會發生?

我設置了194dp的寬度和64dp的高度。改變這些值什麼也不做。爲什麼這不會影響ImageButton的實際寬度和高度?

當使用圖形編輯器通過按住SHIFT並拖動角來調整按鈕大小時,這不會更改XML中的寬度和高度值,而只會增加邊距。見下面生成的XML:

<ImageButton 
     android1:id="@+id/new_customer_button_selector" 
     android1:layout_width="194dp" 
     android1:layout_height="64dp" 
     android1:layout_alignParentBottom="true" 
     android1:layout_alignRight="@+id/returning_customer_button_selector" 
     android1:layout_marginBottom="408dp" 
     android1:layout_marginRight="86dp" 
     android1:layout_marginTop="89dp" 
     android1:background="@drawable/new_customer_button_selector" 
     android1:contentDescription="@string/back_button_desc" /> 

這是我的最終目標:

enter image description here

請告訴我怎樣才能到達那裏。這個簡單的事情應該更容易。

+0

你有什麼文件夾中的圖像?它只是在Drawable文件夾中嗎?如果是這樣,操作系統將假設1像素= 1 DIP,這不是你想要的。 – CaseyB

+0

是的,它們在/ res/drawable中。那我該怎麼做? –

+0

你應該嘗試將它們分成正確的分辨率文件夾。看看這個鏈接的更多信息:http://developer.android.com/guide/practices/screens_support.html – CaseyB

回答

0

閱讀developer.android.com/guide/practices/screens_support.html上提供的信息後,我現在瞭解4種不同類型的屏幕密度。感謝CaseyB的鏈接。

我使用我在http://members.ping.de/~sven/dpi.html發現的實用程序,在大約160時計算了我的屏幕密度。

我的問題是由AVD管理器創建的默認AVD將LCD密度設置爲240(高)。

將它設置爲160後,我的項目與按鈕呈現正確的大小。

因爲我正在開發1個屏幕分辨率和密度,所以我將所有drawables留在了drawables文件夾中。如果我決定使用其他平板電腦,那麼我可能會使用其他文件夾。

提示:不要依靠Eclipse圖形編輯器進行資產對齊或調整大小。我不確定它是否完全準確。我使用舊的編輯XML並在嘗試調整大小和間距時運行項目方法。