[英]Aligning a image button with a background 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>
你总是可以尝试使用px
代替dp
,但是整点dp
是,他们将自动缩放为任何屏幕。 如果您使用px
我怀疑它只能在您正在测试的当前屏幕分辨率下正常工作。 您必须为多种屏幕分辨率/密度定义px
值,以确保您的应用在不同设备上正确显示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.