2014-06-19 40 views

回答

3

我相信最簡單的方法是將ImageViewImageButton都包裝在FrameLayout中。例如:

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/your_image" /> 
    <ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:gravity="center" /> 
</FrameLayout> 
1

您可以在某些佈局中重疊視圖(例如FrameLayoutRelativeLayout)。

只需在xml佈局中放置兩個視圖,以便重疊(例如對於FrameLayout,寬度和高度均爲match_parent)。最後一個添加到頂部。

0

最簡單的方法是隻使用ImageButton

ImageButton具有用於背景圖像

src屬性用於在前景圖像一個background屬性。

在StackOverflow上查看此存在example

<ImageButton 
    android:id="@+id/ImageButton01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/album_icon" 
    android:background="@drawable/round_button" /> 

enter image description here

0

或者您可以使用一個RelativeLayout像matiash說:

下面是一個自定義標題含有個人資料的Facebook圖片抽屜式導航的示例代碼

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:facebook="http://schemas.android.com/apk/res-auto" 
android:id="@+id/customHeader" 
android:layout_width="match_parent" android:layout_height="match_parent"> 

<ImageView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:src="@drawable/green_gradient"/> 

<com.facebook.widget.ProfilePictureView 
    android:id="@+id/leftPic" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentBottom="true" 
    facebook:preset_size="small" 
    android:paddingBottom="4dp" 
    android:paddingLeft="3dp" 
    /> 

</RelativeLayout> 

enter image description here

結果

您可以添加ImageButton的,你想,只需添加以下代碼到你的佈局

<ImageButton 
android:id="@+id/myImageButton 
android:layout_width="SET YOUR WIDTH" 
android:layout_height="SET YOUR HEIGHT" 
android:background="ADD YOUR BACKGROUND" /> 
相關問題