[英]How to remove gap between components using Grid Layout in Eclipse RCP?
[英]How to remove space in between Android Grid Layout
如标题所示,我只想拥有一个布局,而网格布局中的列/行之间的空间很小甚至没有。 请参考下图作为示例。 我只是希望所有按钮占用它们所在单元格的所有空间,而相邻的单元格彼此相对。 这将使外观更加平整。
我看了这个问题: GridLayout(不是GridView)如何均匀地拉伸所有子项 -以及: GridLayout(不是GridView)-单元之间的空间
但这并不能解决我的问题。 非常感谢您的帮助和建议。
这是我的gridLayout XML代码。
GridLayout
android:id="@+id/grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#32ffffff"
android:rowOrderPreserved="false"
android:columnCount="3"
android:padding="10dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true">
<Button
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="0"
android:text="Hello"
android:layout_columnWeight="1"
android:layout_columnSpan="2"
android:layout_gravity="fill"
android:padding="5dp"/>
<Button
android:id="@+id/sorry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_row="1"
android:layout_gravity="fill"
android:text="Sorry" />
<Button
android:id="@+id/thank"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="1"
android:layout_gravity="fill"
android:text="Thank You" />
<Button
android:id="@+id/myname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My \nName \nIS"
android:layout_column="2"
android:layout_row="0"
android:layout_rowSpan="2"
android:layout_rowWeight="1" />
<Button
android:id="@+id/howto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="How To Say ..?"
android:layout_columnSpan="2"
android:layout_column="0"
android:layout_row="2"
android:layout_columnWeight="1"
android:layout_gravity="fill"/>
<Button
android:id="@+id/welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="2"
android:text="You're\nWelcome" />
<Button
android:id="@+id/yourname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Name?"
android:layout_column="0"
android:layout_row="3"
android:layout_gravity="fill"
/>
<Button
android:id="@+id/howareyou"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="How are you?"
android:layout_columnSpan="2"
android:layout_column="1"
android:layout_row="3"
android:layout_columnWeight="1"
android:layout_gravity="fill"/>
<Button
android:id="@+id/english"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Do you speak english?"
android:layout_columnSpan="3"
android:layout_column="0"
android:layout_row="4"
android:layout_columnWeight="1"
android:layout_gravity="fill"/>
</GridLayout>
按钮具有默认的填充。您可以设置背景进行更改。
<GridLayout
android:id="@+id/grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#32ffffff"
android:columnCount="3"
android:padding="10dp"
android:rowOrderPreserved="false">
<Button
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnSpan="2"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="0"
android:background="#ffffff"
android:padding="5dp"
android:text="Hello" />
<Button
android:id="@+id/sorry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_row="1"
android:background="#ffffff"
android:text="Sorry" />
<Button
android:id="@+id/thank"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_gravity="fill"
android:layout_row="1"
android:background="#ffffff"
android:text="Thank You" />
<Button
android:id="@+id/myname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="0"
android:layout_rowSpan="2"
android:layout_rowWeight="1"
android:background="#ffffff"
android:text="My \nName \nIS" />
<Button
android:id="@+id/howto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnSpan="2"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="2"
android:background="#ffffff"
android:text="How To Say ..?" />
<Button
android:id="@+id/welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="2"
android:background="#ffffff"
android:text="You're\nWelcome" />
<Button
android:id="@+id/yourname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="fill"
android:layout_row="3"
android:background="#ffffff"
android:text="Your Name?" />
<Button
android:id="@+id/howareyou"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_columnSpan="2"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="3"
android:background="#ffffff"
android:text="How are you?" />
<Button
android:id="@+id/english"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_columnSpan="3"
android:layout_columnWeight="1"
android:layout_gravity="fill"
android:layout_row="4"
android:background="#ffffff"
android:text="Do you speak english?" />
</GridLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.