【问题标题】:Vertically Space "Weight" between Linear Layout Buttons线性布局按钮之间的垂直空间“权重”
【发布时间】:2021-08-19 10:05:05
【问题描述】:

我想知道如何在按钮之间垂直添加空间,我在跟着教练,他屏幕上的按钮看起来不错。另外,当我下载他的项目文件时,问题仍然存在。

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

【问题讨论】:

  • 尝试用 androidx.appcompat.widget.AppCompatButton 替换 Button

标签: java android android-studio kotlin android-activity


【解决方案1】:

您想在加权视图或任何其他类型的视图中的按钮之间添加边距。解决方案是您要添加我在下面写的行。


水平边距

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

如果,我解决了你的问题,请给这个答案打勾并投票。提前致谢。 ;)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    • 2023-03-22
    • 1970-01-01
    相关资源
    最近更新 更多