0

我想創建一個簡單的國旗遊戲。你會得到國家名稱,然後你必須猜出正確的標誌。在我的播放屏幕上,我有一個TextView和一個TableLayout,兩行中有4個圖像。這些圖像是相同的尺寸。TextView縮小TableLayout

問題是:TextView「縮小」了第二個TableRow,因此圖像不再是同樣大的。如果我刪除TextView,一切都很好。

我試圖在數字體系瀏覽器,它告訴我,第二的TableRow的財產mMeasuredHeight有一個非常高的值的值(16777526)

我的遊戲活動XML調試:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:padding="4dp" 
    tools:context=".PlayTimeModeActivity" > 

    <TextView 
     android:id="@+id/tvFlagName" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="Hello" 
     android:textSize="50dp" /> 

    <TableLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center_horizontal" > 

     <TableRow> 

      <ImageView 
       android:id="@+id/ivFlag1" 
       android:layout_margin="4dp" 
       android:contentDescription="@string/cdFlag1" /> 

      <ImageView 
       android:id="@+id/ivFlag2" 
       android:layout_margin="4dp" 
       android:contentDescription="@string/cdFlag2" /> 
     </TableRow> 

     <TableRow> 

      <ImageView 
       android:id="@+id/ivFlag3" 
       android:layout_margin="4dp" 
       android:contentDescription="@string/cdFlag3" /> 

      <ImageView 
       android:id="@+id/ivFlag4" 
       android:layout_margin="4dp" 
       android:contentDescription="@string/cdFlag4" /> 
     </TableRow> 
    </TableLayout> 
</LinearLayout> 

你需要額外的信息嗎?

我不知道這種佈局的圖像可以做得更好嗎?

編輯: 的圖像是相當高的分辨率

回答

0

試試這個:

讓您的佈局(LinearLayout)的根具有以下屬性android:layout_width="match_parent"android:layout_height="match_parent"

設置你的TableLayoutandroid:layout_height="wrap_content" 。這將使文本放置後佔用屏幕上的任何剩餘空間,而不是壓縮Hello文本。

對於每個TableRow添加android:layout_weight="1"。這將使每行在TableLayout中佔用一定的空間。

對於表中的每個ImageView,設置android:layout_weight="1"。同樣,這將爲每個標誌設置一個均勻的空間。

該標誌應相應縮放。如果縮放比例不正確,請在ImageView中嘗試android:scaleType的不同值。