2015-08-15 8 views
1

У меня проблема с макетом android. Для AlerDialog я построил пользовательский вид: Android - макет вес заполняет весь экран

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingBottom="20dp" 
    android:text="@string/new_game" 
    android:textAppearance="?android:attr/textAppearanceLarge" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/random" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:stretchColumns="1"> 

    <TableRow> 

     <Button 
      style="?android:attr/borderlessButtonStyle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/players2" 
      android:textColor="@color/secondary_text" /> 

     <Button 
      style="?android:attr/borderlessButtonStyle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/players4" 
      android:textColor="@color/secondary_text" /> 

    </TableRow> 

    <TableRow> 

     <Button 
      style="?android:attr/borderlessButtonStyle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/players6" 
      android:textColor="@color/secondary_text" /> 

     <Button 
      style="?android:attr/borderlessButtonStyle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/players8" 
      android:textColor="@color/secondary_text" /> 

    </TableRow> 
</TableLayout> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="20dp" 
    android:text="@string/friends" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:stretchColumns="1"> 

    <TableRow> 

     <Button 
      style="?android:attr/borderlessButtonStyle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/players2" 
      android:textColor="@color/secondary_text" /> 

     <Button 
      style="?android:attr/borderlessButtonStyle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/players4" 
      android:textColor="@color/secondary_text" /> 

    </TableRow> 

    <TableRow> 

     <Button 
      style="?android:attr/borderlessButtonStyle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/players6" 
      android:textColor="@color/secondary_text" /> 

     <Button 
      style="?android:attr/borderlessButtonStyle" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:text="@string/players8" 
      android:textColor="@color/secondary_text" /> 

    </TableRow> 
</TableLayout> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="20dp" 
    android:text="@string/more" 
    android:textAppearance="?android:attr/textAppearanceMedium" /> 


<Button 
    style="?android:attr/borderlessButtonStyle" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/computer" 
    android:textColor="@color/secondary_text" /> 

К сожалению, результаты TableLayout в диалоге, который заполняет весь экран. Поэтому я не хочу использовать неиспользуемое пространство. Вот пример: http://i.stack.imgur.com/unc9g.png

У вас есть идея, что мне нужно изменить, чтобы получить неиспользуемое пространство?

Благодаря

ответ

0

Попробуйте изменить свой топ компоновщика layout_height к wrap_content
попробовать Также это:

dlg.getWindow().setLayout(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); 

С dlg ваш диалог, прежде чем шоу.

Надеюсь, это сработает для вас.

0

Проверьте ваш лучший макет уровень не использует match_parent или fill_parent, как это высота. Также вы можете настроить гравитацию макета верхнего уровня на «центр» или «center_vertical», чтобы центрировать макет и сделать его намного более чистым.

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