2015-02-06 57 views
0

我想在我的tablelayout视图中设置背景颜色,但我不能,因为它没有绘制整个屏幕。我的目标是在屏幕的中心(水平和垂直)和背景蓝色有2个圆形按钮。 我现在所拥有的是这样的:Android:TableLayout中的背景颜色

enter image description here

背景颜色不填充所有屏幕。

,我有以下代码:

<TableLayout 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:layout_gravity="center" 
    android:background="#8ad5f0" 
    tools:context="com.converter.android.dailyhoroscope.SignActivity"> 

    <Button 
     android:text="Extensive" 

     android:background="@drawable/default_button_selector" 
     android:layout_width="102dp" 
     android:layout_height="97dp" 
     android:gravity="center" 
     android:textStyle="bold" 
     android:onClick="onClick" 
     android:layout_marginBottom="4dip" 
     android:id="@+id/extensive" 
     android:textColor="#079dd0" 
     android:textSize="12dp"/> 

如果我改变了以下2行match_parent:

android:layout_width="match_parent" 
    android:layout_height="match_parent" 

我得到这个:

enter image description here

你有什么想法我该如何解决这个问题?

回答

0

尝试把你的tablelayout成FrameLayout里,像这样的:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      xmlns:tools="http://schemas.android.com/tools" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_gravity="center" 
      android:background="#8ad5f0" 

<TableLayout android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:background="#8ad5f0" 
      tools:context="com.converter.android.dailyhoroscope.SignActivity"> 

<Button 
    android:text="Extensive" 

    android:background="@drawable/default_button_selector" 
    android:layout_width="102dp" 
    android:layout_height="97dp" 
    android:gravity="center" 
    android:textStyle="bold" 
    android:onClick="onClick" 
    android:layout_marginBottom="4dip" 
    android:id="@+id/extensive" 
    android:textColor="#079dd0" 
    android:textSize="12dp"/> 
</TableLayout> 
</FrameLayout> 
0

可能你会使用android:layout_weight =“1”。在按钮属性中。

+0

不工作:\ – porthfind 2015-02-06 13:37:15

0

你可以做一个小把戏,而不是正确的代码:-)

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_gravity="center" 
android:background="#8ad5f0" 
tools:context="com.converter.android.dailyhoroscope.SignActivity"> 
<View android:layout_weight="1"> 

</View> 

<Button 
    android:text="Extensive" 
    android:background="#F90" 
    android:layout_width="102dp" 
    android:layout_height="97dp" 
    android:gravity="center" 
    android:textStyle="bold" 
    android:onClick="onClick" 
    android:layout_marginBottom="4dip" 
    android:id="@+id/extensive" 
    android:textColor="#079dd0" 
    android:textSize="12dp"/> 

<Button 
    android:text="blabla" 

    android:background="#F90" 
    android:layout_width="102dp" 
    android:layout_height="97dp" 
    android:gravity="center" 
    android:textStyle="bold" 
    android:onClick="onClick" 
    android:layout_marginBottom="4dip" 
    android:id="@+id/blabla" 
    android:textColor="#079dd0" 
    android:textSize="12dp" 
    /> 

<View android:layout_weight="1"> 

</View>