在 Android Studio 中将 TextView 与其背景的边缘分开
Separating TextView from the edges of its background in Android Studio
问题已经在标题中说的差不多了。
如何将文本与其背景的边缘分开?如果高和宽是wrap_content,就紧挨着文字。我想在那里有一个分离。如果我使用特定数字,我觉得它在不同设备上看起来会有所不同。
编辑: 正如我看到有些人在评论中感到困惑,我的意思是填充。我只是想不出那个词,但现在我知道了,因为另一个用户在那里做了一个答案。
如果你只是需要"Separate"它从BACKGROUND的边缘,你可以设置一个padding/margin到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>
它将如下所示:
问题已经在标题中说的差不多了。
如何将文本与其背景的边缘分开?如果高和宽是wrap_content,就紧挨着文字。我想在那里有一个分离。如果我使用特定数字,我觉得它在不同设备上看起来会有所不同。
编辑: 正如我看到有些人在评论中感到困惑,我的意思是填充。我只是想不出那个词,但现在我知道了,因为另一个用户在那里做了一个答案。
如果你只是需要"Separate"它从BACKGROUND的边缘,你可以设置一个padding/margin到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>
它将如下所示: