2010-12-08 6 views
1

私はAndroid用のプログラムを作成していて、各セルにボタンがある3x7(3列、7行)テーブルを作成します。私はアンドロイドでフルスクリーンテーブルを作るにはどうすればいいですか?

私はtableLayoutを使用しようとしましたが、テーブルの幅が常に短すぎたり長すぎたりすると、空白またはボタンがページから外れることがあります。私は高さ、ただの幅に問題がありません。

この問題は、JavaのGridLayoutのようなレイアウトでも簡単に解決できます。 Androidと同等の機能はありますか?

ご意見をいただければ幸いです。

答えて

2

重みのある線形レイアウトを使用する必要があります。

少し試してみても問題ありませんが、正しい方向に向ける必要があります。

<?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:"fill_parent" android:orientation="vertical"> 
    <LinearLayout android:layout_width:"fill_parent" android:layout_height:"fill_parent" android:orientation="vertical"> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1"> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
     </LinearLayout>  
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
     </LinearLayout> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
     </LinearLayout> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
     </LinearLayout> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
     </LinearLayout> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
     </LinearLayout> 
     <LinearLayout 
      android:orientation="horizontal" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1"> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
      <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
        android:text="ButtonText"/> 
     </LinearLayout> 
    </LinearLayout> 
</LinearLayout> 
</LinearLayout> 
+0

うわー、ありがとう!それは本当に役に立ちました。 – mattdee123

+2

喜んで助けてください。それが成功した場合、回答を受け入れたものとしてマークする必要があります。 – blindstuff

0

多分設定のandroid:固定サイズであなたのボタンのlayout_width "185dp"

関連する問題