2011-04-14 65 views
0

我有三个GrindViews的活动。我用自定义SimpleCursorAdapters填充这些视图。在每个单元格中都有按钮,我需要将它拉伸到GrindView的单元格中。而且我也需要在GrindViews之间没有空闲空间。我已经尝试设置填充/边距而不起作用。这里有个XML:如何拉伸按钮以适合GridView

的MainView:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 

<GridView android:id="@+id/gridview1" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:numColumns="5" 
    android:gravity="center" /> 

<GridView android:id="@+id/gridview2" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:numColumns="5" 
    android:gravity="center" /> 

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview3" android:layout_width="fill_parent" 
    android:layout_height="wrap_content" android:numColumns="4" 
    android:gravity="center" /> 

细胞:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" android:padding="1dip" 
android:layout_height="fill_parent" android:orientation="horizontal"> 

<Button xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:padding="1dip" 
    android:layout_height="fill_parent" android:id="@+id/textButton" /> 

截图: Current Status

感谢您的帮助!

+0

该死的,我希望了解一些性感的新GrindView!我不确定我是否明白你想要做什么。解决方案是否可能只是从您的单元格的LinearLayout和Button中删除android:padding =“1dip”? – 2011-04-16 00:25:48

+0

也许这张截图会更好[链接](http://img593.imageshack.us/i/devicelo.png/)。我只想伸展按钮来覆盖整个橙色区域。所以他们周围几乎没有黑色背景。如果我从按钮(单元格)删除填充,会发生这种情况 - [链接](http://img64.imageshack.us/i/devicefb.png/) – Warlock 2011-04-16 09:32:52

回答

0

我想你必须为你的按钮设置你自己的可绘制图像,而不是使用标准系统图像。除非我错了,否则按钮的标准MDPI图像具有水平边上3像素,顶部1像素和底部4像素的内置透明边框。所以,即使这个按钮图像完全展开为100%填充了一个网格单元格,它仍然会包含此透明边框,因此不会完全填充该单元格。 (这是基于假定默认按钮图像是btn_default_normal.9.png。)

而不是使用按钮,看看ImageButton,它允许您设置自己的图像。或者,要使用常规的Button,您可能需要使用可绘制的状态列表来设置按钮的背景图像。请参阅“按钮样式”部分了解更多信息。

-

不过,我现在看到的文档“明确设定填充值将覆盖在后台找到了相应的填充。”我看到你提到你尝试设置填充,但你是否尝试将填充设置为零?

+0

你说得对。设置我自己的按钮背景图像有助于整个区域的覆盖。谢谢你的答案! fyi - 将填充设置为零并没有帮助。 – Warlock 2011-04-19 11:15:26