2014-06-19 42 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" /> 
相关问题