Android怎么让LinearLayout的两个按钮之间存在一些间隔

 我来答
changyiduU4Q
高粉答主

2019-08-10 · 关注我不会让你失望
知道答主
回答量:264
采纳率:100%
帮助的人:7.9万
展开全部

可以按照以下代码进行尝试:

<?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="wrap_content"
android:orientation="vertical"
android:padding="10dp"
>

<Button
android:id="@+id/btnAction1"
android:layout_width="fill_parent"

android:layout_height="wrap_content"
android:background="@drawable/cool_button"
android:text = "HiText1"
/>

<Button android:layout_marginTop="50dp"
android:id="@+id/btnAction2"
android:layout_width="fill_parent"

android:layout_height="wrap_content"
android:background="@drawable/cool_button"

android:text="HiText2"
android:layout_below="@id/btnAction1"

/>        

</LinearLayout>

扩展资料

若设置一个控件为android:graviity="center|top" 那么这个控件中的子控件位于该控件的中心位置靠上的部位。

若设置一个控件为android:layout_gravity="center|top" 那么这个控件位于他父控件的中心位置靠近上的部位,是对这个控件本身位置的操作。

android:layout_marginBottom:离某元素底边缘的距离

android:layout_marginLeft:离某元素左边缘的距离

android:layout_marginRight:离某元素右边缘的距离

android:layout_marginTop:离某元素上边缘的距离

膸茽派覞呐Ci
推荐于2017-09-29 · TA获得超过356个赞
知道小有建树答主
回答量:599
采纳率:50%
帮助的人:258万
展开全部
属性:Margin 或者padding

android:layout_margin
一个组件与相邻组件的距离
top,bottom,left,right

android:layout_padding
组件内部内容与组件边界的距离
top,bottom,left,right
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
不爱惜饭5A
2022-01-20
知道答主
回答量:4
采纳率:0%
帮助的人:1505
展开全部

也可以换个思路嘛,在两个Button之间加一个空白的View隔开不就行了

Android Studio

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
huanglenzhi
2015-01-25 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
采纳数:117539 获赞数:517161
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。

向TA提问 私信TA
展开全部
试试下面的代码:

<?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="wrap_content"
android:orientation="vertical"
android:padding="10dp"
>
<Button
android:id="@+id/btnAction1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/cool_button"
android:text = "HiText1"
/>

<Button android:layout_marginTop="50dp"
android:id="@+id/btnAction2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/cool_button"
android:text="HiText2"
android:layout_below="@id/btnAction1"
/>

</LinearLayout>
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
匿名用户
2018-12-14
展开全部
下面的代码那位楼主说得对,就是不全面,我们设置间距要看清楚是给哪个设置间距,再去行动
属性:Margin 或者padding

android:layout_margin
一个组件与相邻组件的距离
top,bottom,left,right

android:layout_padding
组件内部内容与组件边界的距离
top,bottom,left,right
我的代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="登录"
android:layout_gravity="center"
android:layout_margin="30dp"/>

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="注册"
android:layout_gravity="center"
android:layout_margin="30dp"/>
</LinearLayout>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(5)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式