如何在 Android 布局中创建叠加按钮

How do I create overlay button in my Android layout

我想创建一个将覆盖在 2 个布局之间的按钮。 我正在使用线性布局并为其添加了适当的权重。 已附上屏幕截图以供参考。

这是我的 XML tag.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:weightSum="100" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="30"
    android:background="@color/greyColor"
    android:gravity="center" >

    <ImageView
        android:id="@+id/ximgvwCamera"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/camera_big" />
</RelativeLayout>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="70"
    android:background="@android:color/white" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@android:color/white"
        android:gravity="center_horizontal"
        android:orientation="vertical" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:layout_margin="5dp"
            android:padding="5dp"
            android:text="@string/strQ1"
            android:textAppearance="@android:style/TextAppearance.Medium"
            android:textColor="@android:color/darker_gray" />
    </LinearLayout>
</ScrollView>

请帮帮我。 提前致谢!

您需要一个相对布局。设置图片右上对齐,适当设置margin top。

 <RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >

    <ImageView
        android:id="@+id/first"
        android:layout_width="fill_parent"
        android:layout_height="70dp"
        android:src="@drawable/firstImage" />

    <ImageView
        android:layout_width="20dp"
        android:layout_height="20dp"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="5dp"
        android:src="@drawable/middleImage" >
    </ImageView>

    <RelativeLayout
        android:id="@+id/second"
        android:layout_width="fill_parent"
        android:layout_height="70dp"
        android:layout_below="@id/first"
        android:src="@drawable/share_over" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="20dp"
            android:orientation="horizontal" >

            <ImageView
                android:id="@+id/YES"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/YES" />

            <ImageView
                android:id="@+id/NO"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/NO" />
        </LinearLayout>
    </RelativeLayout>
</RelativeLayout>

将您的图片从上-中-下(布局)分开。你的尺寸看起来像上面但是 您可以更改 width/height 大小。

试试这个它会工作...

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="150dp" >

        <ImageView
            android:id="@+id/imageCover"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY"
            android:src="@drawable/image_top" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:background="@drawable/image_bottom"
        android:layout_height="match_parent" >
    </LinearLayout>
</LinearLayout>

<ImageView
    android:id="@+id/imageProfile"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_gravity="end"
    android:layout_marginTop="100dp"
    android:src="@drawable/ic_launcher" />

</FrameLayout>

这样看