简体   繁体   English

线性布局按钮之间的垂直空间“权重”

[英]Vertically Space "Weight" between Linear Layout Buttons

在此处输入图像描述

I was wondering how to add space between buttons vertically, I was following instructor and the buttons on his screen seems good.我想知道如何在按钮之间垂直添加空间,我跟着教练,他屏幕上的按钮看起来不错。 Also, when I downloaded his project files the problem still facing me.另外,当我下载他的项目文件时,我仍然面临着这个问题。

I am new to this weight technology in XML.我是 XML 中这种重量技术的新手。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical">

    <TextView
        android:id="@+id/tvInput"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:background="#EFEFEF"
        android:textSize="48sp"
        android:maxLength="12"
        />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="2dp"
        android:layout_weight="1"
        android:orientation="horizontal"
        >
        <Button
            android:id="@+id/btnSeven"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="7"
            android:onClick="onDigit"
            />
        <Button
            android:id="@+id/btnEight"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="8"
            android:onClick="onDigit"
            />
        <Button
            android:id="@+id/btnNine"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="9"
            android:onClick="onDigit"
            />
        <Button
            android:id="@+id/btnDivide"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="/"
            android:onClick="onDigit"
            />



    </LinearLayout>
      
</LinearLayout>

you want to add margin between buttons in weighted view or any other type of view.您想在加权视图或任何其他类型的视图中的按钮之间添加边距。 The solution is you want to add the line which i have written below.解决方案是您要添加我在下面写的行。


for horizontal margin水平边距

android:layout_marginHorizontal="5dp" 
<!--change the dp size prefered your design-->

for vertical margin垂直边距

android:layout_marginVertical="5dp" 
<!--change the dp size prefered your design-->

or if you preferly want to set margin to left, top, right, bottom.或者,如果您希望将边距设置为左、上、右、下。


for left, top, right, bottom margin用于左、上、右、下边距

<!--left-->
android:layout_marginLeft="5dp" 
<!--change the dp size prefered your design-->

<!--top-->
android:layout_marginTop="5dp" 
<!--change the dp size prefered your design-->

<!--right-->
android:layout_marginRight="5dp" 
<!--change the dp size prefered your design-->

<!--bottom-->
android:layout_marginBottom="5dp" 
<!--change the dp size prefered your design-->

if, I solved your problem please give tick mark & up-vote this answer.如果,我解决了你的问题,请给这个答案打勾并投票。 Thanks in advance.提前致谢。 ;) ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM