2011-08-28 82 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的位於頂部,看看它的伎倆。

相關問題