2011-11-11 24 views
0

我想在android中製作一個匹配遊戲佈局。 我在使所有屏幕分辨率的佈局合成時遇到問題。 我想要的是左側主隊的圖像圖標,一個可伸縮的主隊圖像名稱,主隊得分文本,分隔符,客隊比分文本,可延續的隊形圖像名稱,客場球隊的圖像圖標在右邊。 得分應該在中間。我只是無法做到。在嘗試之前,我試圖將主佈局劃分爲3種佈局:主隊佈局,比分佈局和客場佈局 - 沒有獲得預期的結果。One game layout

有人可以幫忙嗎?

這裏是我的一段代碼:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:background="@color/GamesBGColor" > 

    <LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_gravity="center" 
     android:orientation="horizontal" > 

     <ImageView 
      android:id="@+id/homeTeamIcon" 
      android:layout_width="50dip" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:src="@drawable/holonlogo" /> 

     <ImageView 
      android:id="@+id/homeTeamText" 
      android:layout_height="wrap_content"    
      android:layout_gravity="center"    
      android:src="@drawable/holontext" 
      android:layout_width="115dip" 
      android:layout_marginLeft="3dip" /> 

     <TextView 
      android:id="@+id/homeTeamScore" 
      android:layout_width="25dip" 
      android:layout_height="wrap_content" 
      android:text="123" 
      android:textColor = "@color/purple" 
      android:layout_gravity="center" 
      android:textStyle="bold"    
      android:layout_marginLeft="5dip" /> 

     <TextView 
      android:id="@+id/seperator" 
      android:layout_width="10dip" 
      android:layout_height="wrap_content" 
      android:text="-" 
      android:layout_gravity="center" 
      android:layout_marginLeft="7dip" /> 

     <TextView 
      android:id="@+id/awayTeamScore" 
      android:layout_width="25dip" 
      android:layout_height="wrap_content" 
      android:text="122" 
      android:textColor = "@color/red" 
      android:layout_gravity="center" 
      android:textStyle="bold"    
      android:layout_marginLeft="7dip" /> 

     <ImageView 
      android:id="@+id/awayTeamText" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center"    
      android:src="@drawable/jerusalemtext" 
      android:layout_width="115dip" 
      android:layout_marginLeft="3dip"/> 

     <ImageView 
      android:id="@+id/awayTeamIcon" 
      android:layout_width="50dip" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:src="@drawable/jerusalemlogo" /> 

     </LinearLayout> 
</LinearLayout> 

回答

0

如果你希望你的佈局,在不同分辨率的屏幕工作,你應該使用dip爲單位進行上漿他們。例如:

android:layout_marginRight="10dip" 

dip代表與設備無關的像素,並使用這些在你的佈局意味着Android將自動調整你的佈局,這取決於顯示正在運行的應用程序具有設備。

你可以在Supporting Multiple Screens page in the Android Developer Documentation中閱讀這些。這個文件也有處理不同顯示器的其他選項,但我認爲使用dip可能是最簡單的。

+0

正如你所看到的,我確實使用了dip。我的問題是它沒有伸展到一個完整的水平行。在屏幕大於4in的位置右側留有一些空間。例如,如果我增加了主隊名稱的下降,客隊的圖標不適合2.7英寸屏幕並且不在屏幕上。 – ohadinho

+0

在這種情況下,您可以使用Droiddraw來查看物理結構。它會給您一些想法,您應該使用什麼來確定浸泡的準確值,以便解決您的問題。 –

+0

我想使用設計器,但仍然無法弄清楚我是如何根據需要填充一行的。在較低的分辨率下,我在右側溢出,而在更高的分辨率下,我沒有爲文本設置足夠的「dip」。 – ohadinho