2010-12-08 3 views
1

Я работаю над программой для Android, и я хочу сделать таблицу 3x7 (3 столбца, 7 строк), где каждая ячейка удерживает кнопку.Как сделать полноэкранную таблицу в android

Я попытался использовать tableLayout, но каждый раз, когда ширина таблиц всегда слишком короткая или слишком длинная, что означает, что там пустое место или кнопки уходят с страницы. У меня нет проблемы с высотой, просто по ширине.

Эта проблема также может быть легко решена с помощью макета, такого как GridLayout из java. Есть ли эквивалент в 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 2010-12-10 04:13:54

0

может быть установлен андроида: layout_width на вас кнопку размера исправить "185dp"

Смежные вопросы