Android RelativeLayout alignTop doesn't work

╄→尐↘猪︶ㄣ 提交于 2019-12-06 10:39:07

The problem may be in your image or background. I tested with another image and both are aligned along the tops.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.coapps.pico"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

android:orientation="vertical" >

<!-- title layout -->

<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="wrap_content"
    android:layout_height="200dp"
    android:background="@drawable/background_fragment_title"
    >

    <!-- profile picture -->

    <ImageView
        android:id="@+id/fragment_home_profile_picture"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:src="@drawable/falcao_large"
        android:contentDescription="@string/app_name"
        android:scaleType="fitXY"
        />

    <!-- user name -->

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/fragment_home_profile_picture"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/fragment_home_profile_picture"
        android:gravity="top"
        android:textColor="@android:color/white"
        android:text="Roi Mozer"

        android:textSize="30sp"/>

</RelativeLayout>

I think problem is image background. The text align to top of background

Here you go

Add padding to the textView,

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!