我正在尝试在RelativeLayout 中使用alignTop 属性,以便将文本设置在个人资料图片的右侧 - 与图片的顶部对齐。
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<!-- Home fragment layout -->
<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:background="@color/background_dark_green"
android:orientation="vertical" >
<!-- title layout -->
<RelativeLayout
android:id="@+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
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:background="@drawable/background_profile_picture"
android:contentDescription="@string/app_name"
android:scaleType="fitXY"
android:src="@drawable/test_pic" />
<!-- 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:text="Roi Mozer"
android:textColor="@android:color/white"
android:textSize="30sp"/>
</RelativeLayout>
</RelativeLayout>
这是它在预览中的样子(在手机中也是如此):
As you can see the name center is aligned to picture's top - don't know why..
我怎样才能将它们设置在同一行?
UPDATE:当我将布局高度更改为给定高度(而不是包装内容)时,它确实有效......
问题可能出在您的图像或背景上。我用另一张图像进行了测试,两者都沿着顶部对齐。
<?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>
我认为问题是图像背景。文本与背景顶部对齐
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)