我是Android新手。把一個按鈕放在ImageView上
我想知道是否有可能將一個按鈕或其他組件放在ImageView上。我已經嘗試將圖像設置爲LinearLayout的背景圖像,但是當我在橫向和縱向模式之間切換時,圖像porportions會更改。
非常感謝。
我是Android新手。把一個按鈕放在ImageView上
我想知道是否有可能將一個按鈕或其他組件放在ImageView上。我已經嘗試將圖像設置爲LinearLayout的背景圖像,但是當我在橫向和縱向模式之間切換時,圖像porportions會更改。
非常感謝。
不要將圖像作爲背景,您無法控制圖像的縮放比例。相反,創建一個RelativeLayout,並將一個ImageView作爲其中一個子對象,並且可以將其他RelativeLayout子對象放在任何東西(按鈕等)中。
<RelativeLayout ...>
<ImageView (your image) ...>
<Button (the button you want) ... />
</RelativeLayout>
非常感謝。我希望我可以提高我的Android知識,並幫助其他許多人, – gutiory
似乎資源中的順序很重要,在Button沒有爲我工作的情況下放置ImageView,但上面的順序確實如此。 – EtienneSky
你看過Android Developper的拼圖合併佈局嗎?應該解決你的問題:http://developer.android.com/resources/articles/layout-tricks-merge.html
祝你好運!
鏈接已經死了 – Rule
試試這個代碼...這是幫你....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/imageviewMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="Path "
/>
<Button android:id="@+id/but2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
試試這個代碼.....
在按鈕,讓paramater設置你的按鈕位置....
android:layout_margin or android:layout_alignParent
而且也給圖片的路徑....
最簡單的方法是使用FrameLayout
。
你可以發佈你的代碼嗎? –