在android中,如何将一个项目放在另一个项目后面?

在android中,如何将一个项目放在另一个项目后面?,android,Android,我想在ImageButton后面放置一个ImageView。执行此操作的最佳方式是什么?您可以在某些布局中重叠视图(例如,FrameLayout,RelativeLayout) 只需将两个视图都放在xml布局中,以便重叠(例如,对于FrameLayout,宽度和高度均为匹配父视图)。您添加的最后一个视图位于顶部。您可以在某些布局中重叠视图(例如,FrameLayout,RelativeLayout) 只需将两个视图都放在xml布局中,以便重叠(例如,对于FrameLayout,宽度和高度均为匹配

我想在
ImageButton
后面放置一个
ImageView
。执行此操作的最佳方式是什么?

您可以在某些布局中重叠视图(例如,
FrameLayout
RelativeLayout


只需将两个视图都放在xml布局中,以便重叠(例如,对于
FrameLayout
,宽度和高度均为
匹配父视图)。您添加的最后一个视图位于顶部。

您可以在某些布局中重叠视图(例如,
FrameLayout
RelativeLayout


只需将两个视图都放在xml布局中,以便重叠(例如,对于
FrameLayout
,宽度和高度均为
匹配父视图)。您添加的最后一个位于顶部。

我认为最简单的方法是将
ImageView
ImageButton
包装在
框架布局中。例如:

<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>

我认为最简单的方法是将
图像视图
图像按钮
包装在
框架布局
中。例如:

<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>

最简单的方法是只使用
图像按钮

ImageButton
具有背景图像的
background
属性

以及前景图像的
src
属性

请参阅StackOverflow上的现有内容



最简单的方法是只使用
ImageButton

ImageButton
具有背景图像的
background
属性

以及前景图像的
src
属性

请参阅StackOverflow上的现有内容



或者,您可以使用
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>

结果

您可以在需要的地方添加ImageButton,只需将以下代码添加到布局中

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

或者,您可以使用
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>

结果

您可以在需要的地方添加ImageButton,只需将以下代码添加到布局中

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

我可以对-1发表评论吗?我可以对-1发表评论吗?