2014-03-01 54 views
-1

我遇到了一個小問題:我無法將視圖顯示在右側或左側的屏幕上......在eclipse的圖形佈局預覽中,它看起來像這樣:Android:查看不在正確的地方

Screenshot of eclipse

如果我把它上傳到我的Galaxy Tab 3(10.1" ),它看起來一模一樣...... 這裏的XML的代碼:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:id="@+id/layout" 
    tools:context=".MainActivity" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:gravity="left" 
     android:text="Large Text" 
     android:textAppearance="?android:attr/textAppearanceLarge" /> 

</RelativeLayout> 

正如你所看到的,android:layout_alignParentLeftandroid:layout_alignParentTop設置爲true ...

@dimen/activity_vertical_margin@dimen/activity_horizontal_margin的默認值爲16dp。

它不僅僅關注TextViews,還包括我試用過的所有其他視圖。如果我選擇其他的屏幕尺寸小於10.1" ,認爲是在正確的地方。

任何人都可以幫我嗎?

謝謝!

+2

的墊襯去掉填充 – user2511882

+1

嘗試刪除我們的相對佈局 –

+0

哦左,右補白,這就是它!比你!但是你能說我爲什麼這樣表現嗎?正如我上面寫的,它只在10.1上「像這樣...... – marius

回答

2

從你的RelativeLayout移除這些行

android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
3

試試這個:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/layout" 
tools:context=".MainActivity" > 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:gravity="left" 
    android:text="Large Text" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

您已給予父佈局的填充。這就是爲什麼你不能把你的觀點放在左邊。

2

刪除您的相對佈局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/layout" 
tools:context=".MainActivity" >