在其他人之上显示一个imageview?

时间:2015-10-14 16:11:41

标签: android android-framelayout

我想在其他imageview或视图上方显示一个Imageview。如下图所示。

enter image description here

为了达到这个目的,我编写了代码

<LinearLayout
        android:id="@+id/linear_restaurent_info"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".35"
        android:background="@color/white"
        android:orientation="vertical" >

        <FrameLayout
            android:id="@+id/framelayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <ImageView
                android:id="@+id/frameImage"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_gravity="start"
                android:src="@drawable/demo_pics" />

            <ImageView
                android:id="@+id/imageView_restaurent_pic"
                android:layout_width="70dp"
                android:layout_height="55dp"
                android:layout_gravity="bottom"
                android:layout_marginBottom="-20dp"
                android:layout_marginLeft="10dp"
                android:src="@drawable/icon_search" />
        </FrameLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight=".15"
        android:orientation="vertical" >

        <!-- android:background="@color/Orange" -->

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

            <TextView
                android:id="@+id/restaurent_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:text="Laziz"
                android:textColor="@color/list_restaurent_name_text" />

            <TextView
                android:id="@+id/restaurent_address"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@+id/restaurent_name"
                android:layout_below="@+id/restaurent_name"
                android:layout_marginTop="10dp"
                android:singleLine="true"
                android:paddingLeft="10dp"
                android:text="151 Radford Road, Nottingham, NG7"
                android:textColor="@color/list_restaurent_name_text" />
        </RelativeLayout>
    </LinearLayout>

但无法达到理想的目标。

我的输出如下所示。任何建议表示赞赏。

enter image description here

4 个答案:

答案 0 :(得分:0)

有你的答案:Placing/Overlapping(z-index) a view above another view in android 您不能使用LinearLayout,但可以使用FrameLayout。在FrameLayout中,z-index由添加项的顺序定义。积分给@kcoppock

答案 1 :(得分:0)

我认为你应该尝试相对布局...因为通过使用它你可以把android:layout_above =&#34; @ + id / yourImageIdwhichYouWantToAboveFromAnImage&#34; 我希望通过使用这个你的问题得到解决。!

答案 2 :(得分:0)

您必须使用RelativeLayout为您提供许多关于定位视图的properties。 因此,在我看来,您需要做的就是更改视图的体系结构,以便正确地重新对齐它们。

答案 3 :(得分:0)

你走了。你需要在这里调整一些代码

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:background="#FFFFFF">

    <ImageView
        android:id="@+id/imgCake"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:src="@drawable/image_cake" />

    <ImageView
        android:layout_width="150dp"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="55dp"
        android:src="@drawable/img_laziz"
        android:id="@+id/imgLaziz" />


    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Laziz"
        android:textColor="#000000"
        android:textSize="28sp"
        android:layout_below="@+id/imgCake"
        android:layout_toRightOf="@+id/imgLaziz"
        android:layout_toEndOf="@+id/imgLaziz"
        android:layout_marginLeft="52dp"
        android:layout_marginStart="52dp" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="151 Radford Rasd Nott"
        android:textColor="#000000"
        android:textSize="18sp"
        android:layout_below="@+id/textView"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

</RelativeLayout>

` enter image description here

相关问题