2013-12-13 68 views
0

我沒有看到它,但AVD上的佈局與我預期基於ADT的佈局不同。我有一個圖像按鈕1/3和一個普通按鈕,應該是寬度的2/3。 我創建了一個realtivelayout併爲按鈕設置了一個線性佈局,爲什麼ADT中的佈局與AVD不一樣,我該如何解決這個問題?AVD中的佈局與ADT不同?

This is what i designed in ADT

,這是AVD

on the AVD it's not 1/3 of the screen

<TextView 
    android:id="@+id/textHeaderView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/imageQuoteView" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="18dp" 
    android:text="@string/textHeaderQuote" 
    android:textColor="#FFFFFF" 
    android:textSize="24sp" />  

<TextView 
    android:id="@+id/viewQuote" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/textHeaderView" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="18dp" 
    android:text="@string/textViewQuote" 
    android:textColor="#FFFFFF" 
    android:textSize="20sp" /> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_alignParentBottom="true" 
    android:paddingLeft="0dp" 
    > 

<ImageButton 
    android:id="@+id/btnShare" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:background="#CCCCCC" 
    android:contentDescription="@string/btnsharetext" 
    android:onClick="shareQuote" 
    android:src="@android:drawable/ic_menu_share" /> 

<Button 
    android:id="@+id/btnSendQuote" 
    android:layout_weight="2" 
    android:layout_height="80dp" 
    android:onClick="sendQuotePage" 
    android:text="@string/btn_text_sendQuote" 
    android:background="#FEFEFE" /> 

</LinearLayout> 

+0

都是相同大小的屏幕? –

+0

@robin抱歉,你的意思是? AVD只是ADT屏幕的虛擬屏幕,對吧? – alex

回答

1

的AVD(Android虛擬設備)具有ofcourse其屏幕尺寸和resulution。在ADT(Android開發工具)中,您可以在屏幕布局的正上方爲佈局選擇一個屏幕。默認是Nexus one。嘗試設置其他屏幕,看看會發生什麼。

+0

我甚至嘗試過「預覽所有屏幕」,ADT中的佈局與預期的一樣。在AVD和三星s3上,按鈕不覆蓋屏幕的寬度。 – alex

+0

在你的圖片中,我可以看到你沒有設置寬度。使用fill_parent來覆蓋屏幕的寬度 –

1

爲您設置線性佈局的邊距。例如:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_alignParentBottom="true" 
    android:paddingLeft="0dp" 

    android:layout_margin="5dp"> 

至於爲什麼ADT顯示模擬不同於AVD;你看到的ADT對話框是對它看起來像什麼的一個快速表示 - 不是它絕對的樣子。 AVD是一個物理設備的模擬器,這意味着它會給你最準確的視圖。

編輯:其實回答你的問題

至於你按鍵寬度,則需要使用重量父佈局設置它們的相對寬度,以及指定的0

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_alignParentBottom="true" 
    android:paddingLeft="0dp" 

    android:layout_weight="3"> 

<ImageButton 
    android:id="@+id/btnShare" 
    android:layout_height="match_parent" 
    android:layout_weight="1" 
    android:background="#CCCCCC" 
    android:contentDescription="@string/btnsharetext" 
    android:onClick="shareQuote" 
    android:src="@android:drawable/ic_menu_share" 

    android:layout_width="0dp"/> 

<Button 
    android:id="@+id/btnSendQuote" 
    android:layout_weight="2" 
    android:layout_height="80dp" 
    android:onClick="sendQuotePage" 
    android:text="@string/btn_text_sendQuote" 
    android:background="#FEFEFE" 

    android:layout_width="0dp"/> 
</LinearLayout> 
寬度

我個人不會使用他們提供的自動佈局工具(ADT),因爲他們不給你太多的自由。