我想將ImageButtons放在ImageView上: 我試圖用線性佈局來做到這一點,但總是出現在imageview下的按鈕。我怎樣才能做到這一點?ImageView上的ImageButtons [Android]
在此先感謝!
我想將ImageButtons放在ImageView上: 我試圖用線性佈局來做到這一點,但總是出現在imageview下的按鈕。我怎樣才能做到這一點?ImageView上的ImageButtons [Android]
在此先感謝!
這是FrameLayout裏進來它把一個視圖在另一個之上的能力。因此,無論何時將一個孩子添加到框架佈局中,如果存在,下一個孩子將出現在前一個孩子的頂部。
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:src="@drawable/imageview"
android:scaleType="fitCenter"
android:layout_height="250px"
android:layout_width="250px"/>
<LinearLayout
android:id="@+id/widget43"
android:layout_width="fill_parent"
android:layout_height="100px"
android:orientation="horizontal"
>
<ImageButton
android:id="@+id/ImageButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/album_icon" />
<ImageButton
android:id="@+id/ImageButton02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/album_icon"
/>
<ImageButton
android:id="@+id/ImageButton03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/album_icon"
/>
<ImageButton
android:id="@+id/ImageButton04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/album_icon"
/>
</LinearLayout>
</FrameLayout>
幀佈局兒童的佈局重力和重力也可以定製,以便爲這種情況下是具有水平取向的線性layour但首先是圖像視圖!!
您可以使用RelativeLayout並將ImageButton對齊到ImageView bottom。
使用的FrameLayout
https://developer.android.com/reference/android/widget/FrameLayout.html
它是由這樣的第一個孩子是老二下等
你可以把一個ImageView的[matchparent,matchparent] 並在其下含的LinearLayout您的圖像按鈕
Both in the Framelayout
這裏有一個更好的例子:
這裏是XML的例子。我希望它能幫助(在底部見截圖)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView2"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:src="@drawable/pc"
android:scaleType="fitXY" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/imageButton"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="47dp"
android:layout_marginStart="47dp"
android:src="@drawable/phone"
android:scaleType="fitXY" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/imageButton2"
android:layout_alignBottom="@+id/imageButton"
android:layout_centerHorizontal="true"
android:src="@drawable/phone"
android:scaleType="fitXY" />
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/imageButton3"
android:layout_alignTop="@+id/imageButton2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="36dp"
android:layout_marginEnd="36dp"
android:src="@drawable/phone"
android:scaleType="fitXY" />
</RelativeLayout>
</RelativeLayout>
發佈您的相關代碼,以便我們可以看到您構建對象的順序。 – Sam