【问题标题】:Separating TextView from the edges of its background in Android Studio在 Android Studio 中将 TextView 与其背景边缘分离
【发布时间】:2018-12-12 04:39:39
【问题描述】:

这个问题在标题中已经说了很多。

如何将文本与其背景的边缘分开?如果高度和宽度是 wrap_content,它们就在文本旁边。我想在那里分开。如果我使用特定的数字,我觉得它在不同的设备上看起来会有所不同。

编辑: 我看到有些人对 cme​​ts 感到困惑,我的意思是填充。我只是想不出那个词,但现在我得到了它,因为另一个用户在下面给出了答案。

【问题讨论】:

  • 呃,你在问什么?
  • 您能否添加示例屏幕截图或其他内容以了解我们您在寻找什么??
  • @MayurKarmur 我认为他正在寻找填充/边距,我发布了答案。
  • 我的意思是填充家伙。很抱歉造成混乱。

标签: java android xml textview


【解决方案1】:

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

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Hello World!"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"/>

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

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

如下所示:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-23
    • 2014-05-27
    • 2021-01-19
    • 2020-08-27
    相关资源
    最近更新 更多