【问题标题】:how can I make a perfect square in android?我怎样才能在android中制作一个完美的正方形?
【发布时间】:2020-11-08 12:23:42
【问题描述】:

我想做一个完美的方形按钮,形状是这样的:

这里,xml是:

<Button
    android:id="@+id/button3"
    android:layout_width="@dimen/box_size"
    android:layout_height="@dimen/box_size"
    android:layout_weight="50"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.598"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.146" />

我想删除线和蓝色方块之间的空白,不知道怎么做。

我尝试制作一个图像按钮,但它也给了我不想要的结果。

【问题讨论】:

标签: android xml


【解决方案1】:

解决这个问题的一种方法(我使用的)是创建一个“布局资源文件”并将其设置为按钮的背景。

例如,您可以这样做:创建一个“custom_background.xml”文件(或您喜欢的任何名称),并在其中写入:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="@color/colorPrimary" />
</shape>

然后添加按钮代码:

android:background="@drawable/button_background"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-06
    • 1970-01-01
    • 2022-01-17
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    相关资源
    最近更新 更多