首页 > 解决方案 > 如何在 Android Studio Kotlin 中放大约束布局周围的边框

问题描述

如图所示,我正在约束布局周围设置边框(浅绿色边框)。如何放大边框,如“RED”(附图)所示我尝试了填充命令,但没有做出任何改变。有人可以建议一个解决方案。谢谢!

<TextView
    android:id="@+id/viewBorder"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:background="@drawable/outside_shape"
    app:layout_constraintBottom_toBottomOf="@id/favoriteButton"
    app:layout_constraintEnd_toEndOf="@+id/favoriteButton"
    app:layout_constraintStart_toStartOf="@id/eventImage"
    app:layout_constraintTop_toTopOf="@id/eventPerson"  />

这是背景形状的代码

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <stroke
        android:width="1dp"
        android:color="#04C187" />

    <padding android:left="6dp"
        android:top="10dp"
        android:right="10dp"
        android:bottom="10dp"/>
</shape>

在此处输入图像描述

标签: androidkotlinandroid-constraintlayout

解决方案


您的边框基本上来自背景形状,只需更改背景形状描边的宽度

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <stroke
        android:width="5dp" <!-- Change the Width Here -->
        android:color="#04C187" />

    <padding android:left="6dp"
        android:top="10dp"
        android:right="10dp"
        android:bottom="10dp"/>
</shape>

推荐阅读