簡體   English   中英

線性布局按鈕之間的垂直空間“權重”

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

在此處輸入圖像描述

我想知道如何在按鈕之間垂直添加空間,我跟着教練,他屏幕上的按鈕看起來不錯。 另外,當我下載他的項目文件時,我仍然面臨着這個問題。

我是 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>

您想在加權視圖或任何其他類型的視圖中的按鈕之間添加邊距。 解決方案是您要添加我在下面寫的行。


水平邊距

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

垂直邊距

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

或者,如果您希望將邊距設置為左、上、右、下。


用於左、上、右、下邊距

<!--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-->

如果,我解決了你的問題,請給這個答案打勾並投票。 提前致謝。 ;)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM