[英]Android: Background color in TableLayout
I'd like to set background color in my tablelayout view and I can't, because it doesnt paint the entire screen. 我想在表格布局视图中设置背景颜色,但我不能设置背景颜色,因为它不会绘制整个屏幕。 My goal is to have 2 circle buttons in the center (horizontally and vertically) of the screen and background blue.
我的目标是在屏幕的中央(水平和垂直)有2个圆形按钮,背景为蓝色。 What I have right now is this:
我现在所拥有的是:
the background color doesn't fill all screen. 背景颜色无法填充所有屏幕。
and I have the following code: 而且我有以下代码:
<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"/>
If I change the following 2 lines to match_parent: 如果我将以下2行更改为match_parent:
android:layout_width="match_parent"
android:layout_height="match_parent"
I get this: 我得到这个:
Do you have any idea how can I solve this? 你知道我该怎么解决吗?
May be you will use android:layout_weight="1". 可能您将使用android:layout_weight =“ 1”。 in button property.
在按钮属性中。
Try putting your tablelayout into a FrameLayout, like this: 尝试将您的表格布局放入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>
You can do a little trick, but is not proper code :-) 您可以做一些技巧,但代码不正确:-)
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.