2014-10-26 104 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