在linearlayout中以相等的间距水平对齐按钮 [英] Align Buttons horizontally with equal spacing in linearlayout

查看:128
本文介绍了在linearlayout中以相等的间距水平对齐按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个线性布局,其中5个按钮以相等的间隔水平放置,但是所有按钮的大小(宽度)都应仅为40dp.

i am trying to make a Linear Layout with 5 buttons horizontally placed with equal spacing, but all the buttons size (width) should be 40dp only.

我尝试过这个:

<LinearLayout   android:id="@+id/button_layout"
                    android:background="#DCE1DC"
                    android:orientation="horizontal"
                    android:weightSum="5"
                    android:layout_width="fill_parent"
                    android:layout_height="70dip">

        <Button     android:id="@+id/button_A"
                    android:layout_weight="1"
                    android:layout_height="60dp"
                    android:layout_width="0dp"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="30dp"/>

        <Button     android:id="@+id/button_B"
                    android:layout_weight="1"
                    android:layout_height="60dp"
                    android:layout_width="0dp"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="30dp"/>

        <Button     android:id="@+id/button_C"
                    android:layout_weight="1"
                    android:layout_height="60dp"
                    android:layout_width="0dp"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="30dp"/>

        <Button     android:id="@+id/button_D"
                    android:layout_weight="1"
                    android:layout_height="60dp"
                    android:layout_width="0dp"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="30dp"/>

        <Button     android:id="@+id/button_E"
                    android:layout_weight="1"
                    android:layout_height="60dp"
                    android:layout_width="0dp"
                    android:layout_gravity="center_vertical"
                    android:layout_marginRight="30dp"
                    android:layout_marginLeft="30dp"/>

    </LinearLayout>

它可以工作,但是我需要按钮的宽度要更小,如何做到这一点?

its working but i need the buttons width to be smaller , how to acheive this?

推荐答案

我想这将解决您的查询...

i guess this will resolve your query...

正如您说的那样,您正在使用Linearlayout,那么您可以做类似...

as you say you are using Linearlayout then you can do something like...

<LinearLayout
android:layout_width="match_parent"
android:layout_height="yourheight"
android:orientation="horizontal">
<Button 
android:id="@+id/button_name"
android:weight="1"
android:layout_height="wrap_content"
android:layout_width="match_parent" />

<Button 
android:id="@+id/button_name"
android:weight="1"
android:layout_height="wrap_content"
android:layout_width="match_parent" />

//add as many buttons as you want 


<Button 
android:id="@+id/button_name"
android:weight="1"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</LinearLayout> 

这篇关于在linearlayout中以相等的间距水平对齐按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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