2011-08-28 83 views
0

我试图在RelativeLayoutTextView以下定位图像,但它不起作用。当我使用android:layout_below设置其位置时。这是我的xml如何在Android中以相对布局设置图像视图的位置?

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:background="#ccc" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<TextView 
android:id="@+id/app_details_1" 
android:text="@string/app_details_1" 
android:textColor="#347" 
android:gravity="center" 
android:textSize="9pt" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
/> 

<ImageView 
android:id="@+id/logo" 
android:src="@drawable/secs" 
android:layout_height="wrap_content" 
android:layout_width="wrap_content" 
android:layout_below="@+id/appdetails_1" <!-- I'm setting it here --> 
/> 

</RelativeLayout> 

相反,它只是将图像放在屏幕的左上角。我如何定位?是layout_below错误的定位码?

回答

4

你的xml有个错误。必须

android:layout_below="@id/app_details_1" 
+1

要完全解释这个:'+ id'是这个id必须被创建的一个快捷方式。引用现有的ID时,它只是'id'。有关此官方文档:http://developer.android.com/guide/topics/ui/declaring-layout.html#id – 2011-08-28 16:02:47

+0

此外,错字'appdetails_1'而不是'app_details_1' – Ronnie

+1

@ user7777777777是的,这是唯一的错误。加号不是错误。 – Michael

0

它应该是好的,但首先尝试使用layout_alignParentTop =“真”为TextView的,以确保TextView的位于顶部,看看它的伎俩。

相关问题