簡體   English   中英

將圖像按鈕與背景android對齊

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM