[英]How to make 2 buttons in xml stick together (cover the whole space) in a linear layout?
I am trying to make 2 buttons in a linear layout appear together or be closer then where there are now against each other but I am struggling to do so. 我试图使线性布局中的2个按钮一起出现,或者比现在彼此靠拢的位置更近,但是我正在努力做到这一点。
below is my xml with what it shows, is it possible to achieve what I want, I would really appreciate if someone could tell me how. 下面是我的xml及其显示的内容,是否有可能实现我想要的内容,如果有人可以告诉我该怎么做,我将不胜感激。
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:text="Person 1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnPerson1" />
<Button
android:text="Person 2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/btnPerson2" />
</LinearLayout>
I want the PERSON 1 button and PERSON 2 button to come closes and or stick together 我希望PERSON 1按钮和PERSON 2按钮关闭或粘在一起
将android:layout_margin =“ 0”添加到按钮
Set negative margin to both buttons. 为两个按钮设置负边距。
android:layout_marginTop=-8dp
android:layout_marginBottom=-8dp
Try this, 尝试这个,
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0dp">
<Button
android:text="Person 1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".5"
android:id="@+id/btnPerson1" />
<Button
android:text="Person 2"
android:layout_marginTop="-12dp"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".5"
android:id="@+id/btnPerson2" />
</LinearLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.