使的LinearLayout按钮之间的同一个空间 [英] make same space between button in linearlayout

查看:223
本文介绍了使的LinearLayout按钮之间的同一个空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有按钮,我希望把相同的空间中的所有按钮之间,所以如果我运行在平板键之间的空间等于鸿沟,我使用的LinearLayout的应用程序,我知道有layout_weight的选择,但我不希望拉伸图标

例如

我的XML code低于

 <的LinearLayout
        机器人:ID =@ + ID / shareLinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_below =@ + ID / btnRequestA prescriptionRefill
        机器人:layout_marginTop =10dp>

        <按钮
            机器人:ID =@ + ID / btnFacebook
            机器人:layout_width =50dp
            机器人:layout_height =50dp
            机器人:背景=@可绘制/ btn_facebook/>

        <按钮
            机器人:ID =@ + ID / btnYoutube
            机器人:layout_width =50dp
            机器人:layout_height =50dp
            机器人:背景=@可绘制/ btn_youtube/>

        <按钮
            机器人:ID =@ + ID / btnTwitter
            机器人:layout_width =50dp
            机器人:layout_height =50dp
            机器人:背景=@可绘制/ btn_twitter/>

        <按钮
            机器人:ID =@ + ID / btnPintrest
            机器人:layout_width =50dp
            机器人:layout_height =50dp
            机器人:背景=@可绘制/ btn_pintrest/>
    < / LinearLayout中>
 

解决方案

您可以使用layout_weight。但是,像你说的按钮将被拉伸的,所以不是用重量上的按钮,在空间(查看)使用。

 <按钮
        机器人:ID =@ + ID / btnFacebook
        机器人:layout_width =50dp
        机器人:layout_height =50dp
        机器人:背景=@可绘制/ btn_facebook/>

    <查看
        机器人:layout_width =0dp
        机器人:layout_height =50dp
        机器人:layout_weight =1/>

    <按钮
        机器人:ID =@ + ID / btnYoutube
        机器人:layout_width =50dp
        机器人:layout_height =50dp
        机器人:背景=@可绘制/ btn_youtube/>

    <查看
        机器人:layout_width =0dp
        机器人:layout_height =50dp
        机器人:layout_weight =1/>

    <按钮
        机器人:ID =@ + ID / btnTwitter
        机器人:layout_width =50dp
        机器人:layout_height =50dp
        机器人:背景=@可绘制/ btn_twitter/>

    <查看
        机器人:layout_width =0dp
        机器人:layout_height =50dp
        机器人:layout_weight =1/>

    <按钮
        机器人:ID =@ + ID / btnPintrest
        机器人:layout_width =50dp
        机器人:layout_height =50dp
        机器人:背景=@可绘制/ btn_pintrest/>
< / LinearLayout中>
 

i have button in that i want to put same space between all button so if i run app in tablet the space between button will equal divide, i am using linearlayout, i know there is layout_weight option but i don't want to stretch icon

for example

my xml code is below

  <LinearLayout
        android:id="@+id/shareLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnRequestAPrescriptionRefill"
        android:layout_marginTop="10dp" >

        <Button
            android:id="@+id/btnFacebook"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/btn_facebook" />

        <Button
            android:id="@+id/btnYoutube"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/btn_youtube" />

        <Button
            android:id="@+id/btnTwitter"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/btn_twitter" />

        <Button
            android:id="@+id/btnPintrest"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/btn_pintrest" />
    </LinearLayout>

解决方案

You can use layout_weight. But like you said Buttons will be stretched, so instead of using weight on Buttons, use on spaces(Views).

    <Button
        android:id="@+id/btnFacebook"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@drawable/btn_facebook" />

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

    <Button
        android:id="@+id/btnYoutube"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@drawable/btn_youtube" />

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

    <Button
        android:id="@+id/btnTwitter"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@drawable/btn_twitter" />

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

    <Button
        android:id="@+id/btnPintrest"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:background="@drawable/btn_pintrest" />
</LinearLayout>

这篇关于使的LinearLayout按钮之间的同一个空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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