使用ImageView重叠布局

时间:2014-04-27 15:25:25

标签: android android-layout user-interface relativelayout

我试图创建以下布局:

enter image description here

RelativeLayout的边框是以矩形形状作为背景实现的,但是我无法让ImageView与RelativeLayout重叠,其中一半在其中,而一半在边界之外。这甚至可以用RelativeLayout(如果不是:我还有什么选择)?

layout.xml     

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

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/imageresource"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"/>

    <RelativeLayout
        android:padding="@dimen/item_inner_margin"
        android:background="@drawable/item_border"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:id="@+id/relativeLayout"
        android:layout_below="@+id/imageView">

        <!-- Stuff in the layout -->

    </RelativeLayout>
</RelativeLayout>

提前致谢

danijoo

1 个答案:

答案 0 :(得分:1)

这可能是您正在寻找的内容:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/darker_gray"
    android:orientation="vertical"
    android:scrollbarAlwaysDrawVerticalTrack="true">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:layout_marginTop="70dp"
        android:background="#fff"
        android:elevation="4dp"
        android:orientation="vertical"
        android:padding="20dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:orientation="vertical"
            android:paddingTop="30dp">

            <!-- add content here -->

        </LinearLayout>
    </RelativeLayout>

    <ImageView
        android:id="@+id/imageview1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="16dp"
        android:background="@android:color/holo_blue_bright"
        android:elevation="4dp"
        />
</RelativeLayout>