Android tablelayout中的行间距
我想做一个6x6的瓷砖游戏。 所以我用6X6ImageView做了一个布局,我觉得这很简单。 但是没有,我在行与行之间留有空格,我已经尝试了一段时间让它们离开,但似乎没有任何效果 以下是我的XML:Android tablelayout中的行间距,android,android-tablelayout,Android,Android Tablelayout,我想做一个6x6的瓷砖游戏。 所以我用6X6ImageView做了一个布局,我觉得这很简单。 但是没有,我在行与行之间留有空格,我已经尝试了一段时间让它们离开,但似乎没有任何效果 以下是我的XML: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ll" android:layout_width="fill_parent" androi
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="0dip"
>
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="30sp"
android:text="@string/game_text" >
</TextView>
<TableLayout
android:id="@+id/TableLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dip"
>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="160dp"
android:layout_height="160dp">
<ImageView
android:id="@+id/row1col1"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row1col2"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row1col3"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row1col4"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row1col5"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row1col6"
android:layout_weight="0.16" >
</ImageView>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/row2col1"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row2col2"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row2col3"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row2col4"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row2col5"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row2col6"
android:layout_weight="0.16" >
</ImageView>
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="0dip">
<ImageView
android:id="@+id/row3col1"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row3col2"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row3col3"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row3col4"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row3col5"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row3col6"
android:layout_weight="0.16" >
</ImageView>
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/row4col1"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row4col2"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row4col3"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row4col4"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row4col5"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row4col6"
android:layout_weight="0.16" >
</ImageView>
</TableRow>
<TableRow
android:id="@+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/row5col1"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row5col2"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row5col3"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row5col4"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row5col5"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row5col6"
android:layout_weight="0.16" >
</ImageView>
</TableRow>
<TableRow
android:id="@+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/row6col1"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row6col2"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row6col3"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row6col4"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row6col5"
android:layout_weight="0.16" >
</ImageView>
<ImageView
android:id="@+id/row6col6"
android:layout_weight="0.16" >
</ImageView>
</TableRow>
</TableLayout>
</LinearLayout>
我想你的问题在于布局和重量。布局的默认布局权重为1,这通常很好,因为您可以使用除以该数字。但是,在您的情况下,每行有6个项目。这意味着你必须将1除以6,得到数字0.1666666,你只需要得到0.16 要解决这个问题,您可以将布局权重设置为6,将每个图像视图的布局权重设置为1试试这个。我刚刚在线性布局中添加了android:layout\u weight=“6”,并将所有的android:layout\u weight=“0.16”更改为android:layout\u weight=“1”
让我知道如果它工作,我没有你的图像加载。如果它不起作用,或者发布一个屏幕截图,其他人可能知道解决方案。使用GridView而不是TableLayout。因此,您可以调整行和列的宽度和高度。是否可以使其自适应,以便根据用户屏幕的不同更改框的大小?Gridview具有Gridview高度和宽度,您可以将其设置为包裹内容
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="0dip"
android:layout_weight="6"
>
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="30sp"
android:text="@string/game_text" >
</TextView>
<TableLayout
android:id="@+id/TableLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dip"
>
<TableRow
android:id="@+id/tableRow1"
android:layout_width="160dp"
android:layout_height="160dp">
<ImageView
android:id="@+id/row1col1"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row1col2"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row1col3"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row1col4"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row1col5"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row1col6"
android:layout_weight="1" >
</ImageView>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/row2col1"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row2col2"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row2col3"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row2col4"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row2col5"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row2col6"
android:layout_weight="1" >
</ImageView>
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="0dip">
<ImageView
android:id="@+id/row3col1"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row3col2"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row3col3"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row3col4"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row3col5"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row3col6"
android:layout_weight="1" >
</ImageView>
</TableRow>
<TableRow
android:id="@+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/row4col1"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row4col2"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row4col3"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row4col4"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row4col5"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row4col6"
android:layout_weight="1" >
</ImageView>
</TableRow>
<TableRow
android:id="@+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/row5col1"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row5col2"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row5col3"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row5col4"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row5col5"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row5col6"
android:layout_weight="1" >
</ImageView>
</TableRow>
<TableRow
android:id="@+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/row6col1"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row6col2"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row6col3"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row6col4"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row6col5"
android:layout_weight="1" >
</ImageView>
<ImageView
android:id="@+id/row6col6"
android:layout_weight="1" >
</ImageView>
</TableRow>
</TableLayout>
</LinearLayout>