2014-10-26 106 views
0

我對android編程非常新,我希望你能幫我解決一些問題。我已經在xml文件中設置了背景,並且正在嘗試將圖像按鈕對齊到我背景的特定區域。我曾嘗試使用密度像素,但它不夠精確,現在按鈕覆蓋了背景的一個區域,我希望可以看到它。任何想法如何我可以解決這個問題?對齊圖像按鈕與背景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" 
    android:background="@drawable/home_background"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:layout_marginTop="93dp" > 

     <ScrollView 
      android:id="@+id/scrollView1" 
      android:layout_width="match_parent" 
      android:layout_height="341dp" > 

      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:orientation="horizontal" > 

       <ImageButton 
        android:id="@+id/imageButton1" 
        android:layout_width="100dp" 
        android:layout_height="100dp" 
        android:layout_marginLeft="30dp" 
        android:layout_marginTop="30dp" 
        android:background="@null" 
        android:scaleType="fitXY" 
        android:src="@drawable/workbench" /> 

      </LinearLayout> 
     </ScrollView> 

    </LinearLayout> 

</LinearLayout> 

回答

0

你總是可以嘗試使用px代替dp,然而dp整點是,他們將擴大自動爲任何屏幕。如果您使用px我懷疑它只能在您正在測試的當前屏幕分辨率上正常工作。您必須爲衆多屏幕分辨率/密度定義px值,以確保您的應用在不同設備上正確顯示。

+0

你知道我會怎麼做嗎? – user3407957 2014-10-26 19:10:56

+0

你可以發佈圖片展示你想要實現的目標嗎? – Philio 2014-10-26 19:32:34

+0

http://postimg.org/image/o1taa8lvh/在這裏查看我有一個比較的視圖 – user3407957 2014-10-26 19:55:11