间隔均匀的出按钮行所需 [英] Evenly spaced out row of buttons required

查看:144
本文介绍了间隔均匀的出按钮行所需的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

3使用行和4列我试图均匀的空间了所有的按钮水平,但都失败了。垂直的罚款。

下面是3个不同的尝试空间出来的按钮,1为每个我的3排。第一行延伸图形(这是不希望的),第二个行不伸展但没有间隔(必须在图形之间的间距),而没有任何间隔的第三延伸。请帮我空间均匀出这些。在这同一地点的其他民族的解决方案都没有奏效。我应该尝试使用一个表呢?

视觉总结=无拉伸图形:
我想| X X X X |
而不是| XXXX |

 <?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:方向=垂直><的LinearLayout
    机器人:ID =@ + ID / ROW1
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_gravity =中心
    机器人:layout_weight =1
    机器人:比重=中心
    机器人:方向=横向>    <查看
        机器人:layout_width =0dp
        机器人:layout_height =1DP
        1:机器人layout_weight =>
    < /视图>    <按钮
        机器人:ID =@ + ID / A1
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:背景=@绘制/ blanktilesml
        机器人:重力=CENTER_HORIZONTAL | center_vertical
        机器人:SRC =@绘制/ clear64/>    <查看
        机器人:layout_width =0dp
        机器人:layout_height =1DP
        1:机器人layout_weight =>
    < /视图>    <按钮
        机器人:ID =@ + ID / A2
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:背景=@绘制/ blanktilesml
        机器人:重力=CENTER_HORIZONTAL | center_vertical
        机器人:SRC =@绘制/ clear64/>    <查看
        机器人:layout_width =0dp
        机器人:layout_height =1DP
        1:机器人layout_weight =>
    < /视图>    <按钮
        机器人:ID =@ + ID / A3
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:背景=@绘制/ blanktilesml
        机器人:重力=CENTER_HORIZONTAL | center_vertical
        机器人:SRC =@绘制/ clear64/>    <查看
        机器人:layout_width =0dp
        机器人:layout_height =1DP
        1:机器人layout_weight =>
    < /视图>    <按钮
        机器人:ID =@ + ID / A4
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:背景=@绘制/ blanktilesml
        机器人:重力=CENTER_HORIZONTAL | center_vertical
        机器人:SRC =@绘制/ clear64/>    <查看
        机器人:layout_width =0dp
        机器人:layout_height =1DP
        1:机器人layout_weight =>
    < /视图>
< / LinearLayout中><的LinearLayout
    机器人:ID =@ + ID / ROW2
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_gravity =中心
    机器人:layout_weight =1
    机器人:比重=中心
    机器人:方向=横向>    <的LinearLayout
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:比重=中心
        机器人:方向=横向>        <按钮
            机器人:ID =@ + ID / B1
            机器人:layout_width =0dp
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1
            机器人:背景=@绘制/ blanktilesml
            机器人:比重=中心
            机器人:SRC =@绘制/ clear64/>
    < / LinearLayout中>    <的LinearLayout
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:比重=中心
        机器人:方向=横向>        <按钮
            机器人:ID =@ + ID / B2
            机器人:layout_width =0dp
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1
            机器人:背景=@绘制/ blanktilesml
            机器人:比重=中心
            机器人:SRC =@绘制/ clear64/>
    < / LinearLayout中>    <的LinearLayout
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:比重=中心
        机器人:方向=横向>        <按钮
            机器人:ID =@ + ID / B3
            机器人:layout_width =0dp
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1
            机器人:背景=@绘制/ blanktilesml
            机器人:比重=中心
            机器人:SRC =@绘制/ clear64/>
    < / LinearLayout中>    <的LinearLayout
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:比重=中心
        机器人:方向=横向>        <按钮
            机器人:ID =@ + ID / B4
            机器人:layout_width =0dp
            机器人:layout_height =WRAP_CONTENT
            机器人:layout_weight =1
            机器人:背景=@绘制/ blanktilesml
            机器人:比重=中心
            机器人:SRC =@绘制/ clear64/>
    < / LinearLayout中>
< / LinearLayout中><的LinearLayout
    机器人:ID =@ + ID / ROW3
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_gravity =中心
    机器人:layout_weight =1
    机器人:比重=中心
    机器人:方向=横向
    机器人:weightSum =1>    <按钮
        机器人:ID =@ + ID / C1
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =25
        机器人:背景=@绘制/ blanktilesml
        机器人:paddingLeft =10dp
        机器人:SRC =@绘制/ clear64/>    <按钮
        机器人:ID =@ + ID / C2
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =25
        机器人:背景=@绘制/ blanktilesml
        机器人:paddingLeft =10dp
        机器人:SRC =@绘制/ clear64/>    <按钮
        机器人:ID =@ + ID / C3
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =25
        机器人:背景=@绘制/ blanktilesml
        机器人:paddingLeft =10dp
        机器人:SRC =@绘制/ clear64/>    <按钮
        机器人:ID =@ + ID / C4
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =25
        机器人:背景=@绘制/ blanktilesml
        机器人:paddingLeft =10dp
        机器人:SRC =@绘制/ clear64/>
< / LinearLayout中>< / LinearLayout中>


解决方案

试试这个:

 <的LinearLayout
    机器人:ID =@ + ID / ROW1
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_gravity =中心
    机器人:layout_weight =1
    机器人:比重=中心
    机器人:方向=横向>    <的LinearLayout
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:比重=中心>        <的ImageButton
            机器人:ID =@ + ID / A1
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:背景=@机器人:可绘制/ arrow_up_float
            机器人:重力=CENTER_HORIZONTAL | center_vertical
            机器人:SRC =@绘制/ ic_launcher/>
    < / LinearLayout中>    <的LinearLayout
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:比重=中心>        <的ImageButton
            机器人:ID =@ + ID / A2
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:背景=@机器人:可绘制/ arrow_up_float
            机器人:重力=CENTER_HORIZONTAL | center_vertical
            机器人:SRC =@绘制/ ic_launcher/>
    < / LinearLayout中>    <的LinearLayout
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:比重=中心>        <的ImageButton
            机器人:ID =@ + ID / A3
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:背景=@机器人:可绘制/ arrow_up_float
            机器人:重力=CENTER_HORIZONTAL | center_vertical
            机器人:SRC =@绘制/ ic_launcher/>
    < / LinearLayout中>    <的LinearLayout
        机器人:layout_width =0dp
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_weight =1
        机器人:比重=中心>        <的ImageButton
            机器人:ID =@ + ID / A4
            机器人:layout_width =WRAP_CONTENT
            机器人:layout_height =WRAP_CONTENT
            机器人:背景=@机器人:可绘制/ arrow_up_float
            机器人:重力=CENTER_HORIZONTAL | center_vertical
            机器人:SRC =@绘制/ ic_launcher/>
    < / LinearLayout中>
< / LinearLayout中>

尝试一下本作的第一行。同样可以为所有的行来完成,

所以,除非你不想要的图像被拉伸,你需要说唱他们的布局。这样做你会管理间距和绘制会蛮好看的。如果你伸展按钮然后绘制也会相应拉长。

Using 3 rows and 4 columns I have tried to evenly space out all the buttons horizontally but have failed. vertically is fine.

Below are 3 different attempts to space out the buttons, 1 for each of my 3 rows. The first row stretches the graphic (which is unwanted), the second row does not stretch but there is no spacing (spacing between the graphics is required), while the third stretches without any spacing. Please help me to evenly space these out. Other peoples solutions on this same site have not worked. Should I try using a table instead?

Visual summary= without stretching the graphic: I want | x x x x | and not | xxxx |

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
    android:id="@+id/row1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal" >

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>

    <Button
        android:id="@+id/a1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/blanktilesml"
        android:gravity="center_horizontal|center_vertical"
        android:src="@drawable/clear64" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>

    <Button
        android:id="@+id/a2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/blanktilesml"
        android:gravity="center_horizontal|center_vertical"
        android:src="@drawable/clear64" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>

    <Button
        android:id="@+id/a3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/blanktilesml"
        android:gravity="center_horizontal|center_vertical"
        android:src="@drawable/clear64" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>

    <Button
        android:id="@+id/a4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/blanktilesml"
        android:gravity="center_horizontal|center_vertical"
        android:src="@drawable/clear64" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        android:layout_weight=".1" >
    </View>
</LinearLayout>

<LinearLayout
    android:id="@+id/row2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/b1"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/blanktilesml"
            android:gravity="center"
            android:src="@drawable/clear64" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/b2"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/blanktilesml"
            android:gravity="center"
            android:src="@drawable/clear64" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/b3"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/blanktilesml"
            android:gravity="center"
            android:src="@drawable/clear64" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/b4"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="@drawable/blanktilesml"
            android:gravity="center"
            android:src="@drawable/clear64" />
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:id="@+id/row3"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal"
    android:weightSum="1" >

    <Button
        android:id="@+id/c1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:background="@drawable/blanktilesml"
        android:paddingLeft="10dp"
        android:src="@drawable/clear64" />

    <Button
        android:id="@+id/c2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:background="@drawable/blanktilesml"
        android:paddingLeft="10dp"
        android:src="@drawable/clear64" />

    <Button
        android:id="@+id/c3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:background="@drawable/blanktilesml"
        android:paddingLeft="10dp"
        android:src="@drawable/clear64" />

    <Button
        android:id="@+id/c4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight=".25"
        android:background="@drawable/blanktilesml"
        android:paddingLeft="10dp"
        android:src="@drawable/clear64" />
</LinearLayout>

</LinearLayout>

解决方案

Try this:

<LinearLayout
    android:id="@+id/row1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_weight="1"
    android:gravity="center"
    android:orientation="horizontal" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/a1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:drawable/arrow_up_float"
            android:gravity="center_horizontal|center_vertical"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/a2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:drawable/arrow_up_float"
            android:gravity="center_horizontal|center_vertical"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/a3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:drawable/arrow_up_float"
            android:gravity="center_horizontal|center_vertical"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="center" >

        <ImageButton
            android:id="@+id/a4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:drawable/arrow_up_float"
            android:gravity="center_horizontal|center_vertical"
            android:src="@drawable/ic_launcher" />
    </LinearLayout>
</LinearLayout>

try this for your first row. Similarly can be done for all the row,

So unless you don't want the images to be stretched you need to rap them in a layout. Doing so you will manage the spacing and the drawable will look just fine. If you stretch the buttons then the drawable will also be stretched accordingly.

这篇关于间隔均匀的出按钮行所需的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆