为了账号安全,请及时绑定邮箱和手机立即绑定

在 Android Studio 中将 TextView 与其背景边缘分离

在 Android Studio 中将 TextView 与其背景边缘分离

婷婷同学_ 2022-03-10 21:42:28
这个问题在标题中已经说了很多。如何将文本与其背景的边缘分开?如果高度和宽度是 wrap_content,它们就在文本旁边。我想在那里分开。如果我使用特定的数字,我觉得它在不同的设备上看起来会有所不同。编辑:正如我看到有些人在评论中感到困惑,我的意思是填充。我只是想不出那个词,但现在我得到了它,因为另一个用户在那里给出了答案。
查看完整描述

1 回答

?
当年话下

TA贡献1890条经验 获得超9个赞

如果您只需要将其与背景边缘“分离”,您可以将填充/边距设置为TextView


<TextView

    android:layout_width="match_parent"

    android:layout_height="wrap_content"

    android:text="Hello World!"

    android:paddingLeft="10dp"

    android:paddingRight="10dp"/>

既然你提到你有超过 1TextView个彼此相邻这就是你可以做到的。


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent">


    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Hello World!"

        android:paddingLeft="10dp"

        android:paddingRight="10dp"/>

    <TextView

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Hello World TWO!"

        android:paddingLeft="10dp"

        android:paddingRight="10dp"/>

</LinearLayout>

如下所示:

//img1.sycdn.imooc.com//622a005e0001d18603830134.jpg

查看完整回答
反对 回复 2022-03-10
  • 1 回答
  • 0 关注
  • 193 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信