2013-01-17 30 views
0

我真的是android中的newbee。 我只想創建一些帶有textviews和圖片的佈局。Textviews不在正確的地方

我做到了,它在編輯器上看起來不錯。 (我正在使用eclipse/adt)。

當我第一次嘗試,結果是可怕的(見圖片)。之後,我嘗試了另一個配置,但仍然可怕。

據我所知,DP是獨立的,但正如我所看到的那樣。但我想,我犯了一些錯誤。

請幫幫我,開導我,我做錯了什麼,爲什麼textviews和圖片移動?

在圖片從左至右依次爲:

  • 編輯
  • 埃克萊爾,3.3 QVGA分辨率320x480 MDPI
  • 果凍豆3.2 WQVGA 240X400 LDPI

textviews

和我代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:id="@+id/quizLayout" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@drawable/quiz_background" 
tools:context=".Quiz" > 

<Button 
    android:id="@+id/btnGo" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="36dp" 
    android:text="@string/go" /> 

<TextView 
    android:id="@+id/tvQuestion" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:layout_marginLeft="19dp" 
    android:layout_marginTop="60dp" 
    android:text="@string/question" /> 

<TextView 
    android:id="@+id/tvPoints" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/tvQuestion" 
    android:layout_below="@+id/tvQuestion" 
    android:layout_marginTop="31dp" 
    android:text="@string/points" /> 

<ImageView 
    android:id="@+id/imgCarHolder" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignLeft="@+id/tvPoints" 
    android:layout_below="@+id/tvPoints" 
    android:layout_marginTop="26dp" 

    android:contentDescription="@string/dummy" /> 

</RelativeLayout> 
+0

您應該爲不同的屏幕尺寸製作不同的屏幕布局。由於不同屏幕的dp值會發生變化,因此您需要分別設計它們。 –

+0

是否意味着,如果我想在xhdpi,ldpi,mdpi和hdpi上取得成功,並且爲他們創建4張圖片,我應該在4種不同佈局上定義所有視圖4次? – vaso123

+0

如果您在任何佈局文件中使用hight或width或任何其他空間上下文的固定值,我建議您針對每個屏幕大小單獨進行。 例如35 dp對於分辨率爲360 * 480和480 * 640的屏幕而言是不同的。如果您在大範圍內使用常量,則屏幕看起來很奇怪。 –

回答

0

如果您使用任何佈局文件中的高度或寬度或任何其他空間上下文的固定值,我建議您分別爲每個屏幕大小單獨出發。例如對於分辨率爲360 * 480和480 * 640的屏幕,35 dp是不同的。如果您在大範圍內使用常量,則屏幕看起來很奇怪。