将图像按钮与背景android对齐

时间:2014-10-26 17:47:10

标签: android

我对android编程很新,我希望你可以帮我解决一些问题。我在xml文件中设置了一个背景,我试图将图像按钮对齐到我背景的特定区域。我尝试过使用密度像素,但它不够精确,按钮现在覆盖了我希望可见的背景区域。关于如何解决这个问题的任何想法?

非常感谢,

亚历

我的代码如下:

    <?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>

1 个答案:

答案 0 :(得分:0)

您可以随时尝试使用px代替dp,但dp的重点是它们会自动缩放到任何屏幕。如果您使用px,我怀疑它只适用于您正在测试的当前屏幕分辨率。您必须为众多屏幕分辨率/密度定义px值,以确保您的应用在不同设备上正确显示。

相关问题