Space 在文本视图和可绘制图标之间
Space between textview and drawable icon
我遇到了图标位置问题。我将该图标设置为 TextView 的 drawableLeft,这工作正常,但是,如果我将 TextView 的引力设置为 center_horizontal,则图标和文本之间会出现填充 space。代码如下:
<TextView
style="@style/BaseText.White.Bold"
android:gravity="center_horizontal"
android:drawableStart="@drawable/ic_text"
android:drawableLeft="@drawable/ic_text"
android:text="@string/text"
android:layout_marginBottom="@dimen/margin_small"
android:layout_marginRight="@dimen/margin_big"
android:layout_marginLeft="@dimen/margin_big"
android:padding="0dp"
android:drawablePadding="0dp"/>
我必须怎么做才能确保图标显示在文本的左侧但水平居中?
我制作了两个屏幕截图来向您展示添加或删除图标重力时的区别。
当没有设置textview的gravity时,结果如下:
但是,添加引力后,文本和图标之间会出现填充:
提前致谢
Try to give android:gravity="center"
to Text View
. Also add android:layout_width="wrap_content" and android:layout_height="wrap_content"
properties in Text View
.
参考这个。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:drawableLeft="@mipmap/ic_launcher"
android:drawablePadding="0dp"
android:drawableStart="@mipmap/ic_launcher"
android:gravity="center"
android:textSize="22sp"
android:padding="0dp"
android:text="TestingTestingTestingTestingTestingTestingTestingTestingTesting" />
</RelativeLayout>
This is what it showing.
仅在您的文本视图中添加 android:drawablePadding="10dp" 字段参考 coad
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add New Address"
android:textAppearance="@style/Title"
android:id="@+id/tvAddNewAddress"
android:drawablePadding="20dp"
android:layout_weight="1"
android:padding="5dp"
android:textColor="@color/colorAccent"
android:drawableStart="@android:drawable/arrow_down_float"
/>
我遇到了图标位置问题。我将该图标设置为 TextView 的 drawableLeft,这工作正常,但是,如果我将 TextView 的引力设置为 center_horizontal,则图标和文本之间会出现填充 space。代码如下:
<TextView
style="@style/BaseText.White.Bold"
android:gravity="center_horizontal"
android:drawableStart="@drawable/ic_text"
android:drawableLeft="@drawable/ic_text"
android:text="@string/text"
android:layout_marginBottom="@dimen/margin_small"
android:layout_marginRight="@dimen/margin_big"
android:layout_marginLeft="@dimen/margin_big"
android:padding="0dp"
android:drawablePadding="0dp"/>
我必须怎么做才能确保图标显示在文本的左侧但水平居中?
我制作了两个屏幕截图来向您展示添加或删除图标重力时的区别。
当没有设置textview的gravity时,结果如下:
但是,添加引力后,文本和图标之间会出现填充:
Try to give
android:gravity="center"
toText View
. Also addandroid:layout_width="wrap_content" and android:layout_height="wrap_content"
properties inText View
.
参考这个。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:drawableLeft="@mipmap/ic_launcher"
android:drawablePadding="0dp"
android:drawableStart="@mipmap/ic_launcher"
android:gravity="center"
android:textSize="22sp"
android:padding="0dp"
android:text="TestingTestingTestingTestingTestingTestingTestingTestingTesting" />
</RelativeLayout>
This is what it showing.
仅在您的文本视图中添加 android:drawablePadding="10dp" 字段参考 coad
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add New Address"
android:textAppearance="@style/Title"
android:id="@+id/tvAddNewAddress"
android:drawablePadding="20dp"
android:layout_weight="1"
android:padding="5dp"
android:textColor="@color/colorAccent"
android:drawableStart="@android:drawable/arrow_down_float"
/>