如何将ImageView放在RelativeLayout上? [英] How to put ImageView over RelativeLayout?

查看:76
本文介绍了如何将ImageView放在RelativeLayout上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计配置文件布局.为此,我正在使用Imageview和RelativeLayout.我正在尝试将ImageView放在RelativeLayout的顶部.我同时使用了height和android:scaleType ="centerCrop",但在设计编辑器中显示还可以,但是当我编译并运行应用程序时,ImageView始终位于RelativeLayout的后面.

I'm designing a Profile Layout. For which I'm using Imageview and RelativeLayout. I'm trying put ImageView on top of RelativeLayout.I used both elevation and android:scaleType="centerCrop" but it shows okay in the design editor but when I compile and run app then ImageView always stays behind the RelativeLayout.

在设计编辑器中,它显示

In Design Editor it shows

这是我想要的,但是在设备中,它显示如下

Which is what I want but in the device, it shows like this

请帮助.

下面是我的XML文件

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/layout">


        <ImageView
            android:id="@+id/header_cover_image"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:background="#000000"
            android:scaleType="centerCrop"
            android:src="@drawable/nav_menu_heade" />


        <ImageView
            android:clickable="true"
            android:id="@+id/profile"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_below="@+id/header_cover_image"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="-130dp"
            android:scaleType="fitStart"
            android:elevation="8dp"
            android:padding="20dp"
            android:src="@drawable/passport" />


        <RelativeLayout
            android:id="@+id/profile_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/header_cover_image"
            android:background="#eb0772ca"
            android:elevation="2dp"
            android:paddingBottom="2dp">



            <TextView
                android:id="@+id/name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="70dp"
                android:text="Sagar Rawal"
                android:textColor="#fff"
                android:textSize="24sp"
                android:textStyle="bold" />



            <TextView
                android:id="@+id/quote"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/name"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:text="Don't Cry cuz it's over, Smile cuz it happen"
                android:textColor="#ffffff"
                android:textSize="18sp" />
            <TextView
                android:id="@+id/location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/quote"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:text="Jumla, Nepal"
                android:textColor="#ffffff"
                android:textSize="16sp" />

        </RelativeLayout>



    </RelativeLayout>
</ScrollView>

推荐答案

像这样编辑Xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/layout">


        <ImageView
            android:id="@+id/header_cover_image"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:background="#000000"
            android:scaleType="centerCrop"
            android:src="@drawable/back" />


        <RelativeLayout
            android:id="@+id/profile_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/header_cover_image"
            android:background="#eb0772ca"
            android:elevation="2dp"
            android:paddingBottom="2dp">


            <TextView
                android:id="@+id/name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="70dp"
                android:text="Sagar Rawal"
                android:textColor="#fff"
                android:textSize="24sp"
                android:textStyle="bold" />


            <TextView
                android:id="@+id/quote"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/name"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:text="Don't Cry cuz it's over, Smile cuz it happen"
                android:textColor="#ffffff"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/location"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/quote"
                android:layout_centerHorizontal="true"
                android:layout_marginTop="10dp"
                android:text="Jumla, Nepal"
                android:textColor="#ffffff"
                android:textSize="16sp" />

        </RelativeLayout>

        <ImageView
            android:clickable="true"
            android:id="@+id/profile"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_below="@+id/header_cover_image"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="-130dp"
            android:scaleType="fitStart"
            android:elevation="8dp"
            android:padding="20dp"
            android:src="@drawable/app_icon" />


    </RelativeLayout>
</ScrollView>

这篇关于如何将ImageView放在RelativeLayout上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆