drawableleft靠上
时间: 2023-08-05 21:39:41 浏览: 46
要让一个`TextView`的`drawableLeft`靠上,可以通过设置`android:drawablePadding`和`android:gravity`属性来实现。具体做法如下:
1. 设置`android:drawablePadding`属性为一个负值,例如`-10dp`,可以将`drawable`往上移动一定的距离,让它与`TextView`的顶部对齐。
2. 设置`android:gravity`属性为`center_vertical`,这会让`TextView`的文本垂直居中,与`drawable`的顶部对齐。
以下是一个示例代码:
```
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:drawableLeft="@drawable/ic_launcher"
android:drawablePadding="-10dp"
android:gravity="center_vertical" />
```
你可以根据实际情况调整`android:drawablePadding`的值。
相关问题
drawableLeft
drawableLeft是Android中TextView控件的一个属性,它可以让我们在TextView的左侧添加一个图片。如果你想要在TextView的右侧添加图片,可以使用drawableRight属性。
android drawableleft 间距
要设置 Android 中 DrawableLeft 的间距,可以通过设置 TextView 的 `drawablePadding` 属性来实现。例如,以下代码将 DrawableLeft 的间距设置为 20dp:
```
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_icon"
android:drawablePadding="20dp"
android:text="Text with DrawableLeft"/>
```
你可以根据需要调整 `drawablePadding` 的值来改变间距大小。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)