问题描述
我有一个textview,其中包含图像和一些文本.
I have a textview which holds an image and some text.
通过编程,我已将可绘制图像添加到文本视图的左侧
programmatically i have added the drawable image to the left side of text view
txtIDFav.setCompoundDrawablesWithIntrinsicBounds(R.drawable.fav_enabled, 0, 0, 0);
我已使用对齐了文本视图以居中
i have aligned the text view to center using
txtIDFav.setGravity(Gravity.CENTER);
现在,文本视图中的文本将居中对齐.但图片在左侧.
Now the text in the textview is aligned to center. but the image is on the left side.
例如:[image] _____________________ 我的文字
eg: [image]_____________________ mytext
使用_为其提供了不允许的空格.
used the _ to give space as its not allowed.
我想将图像与文本对齐.
I want to align the image to center along with the text.
例如: _____________________ [image]我的文字
eg: _____________________[image]mytext
请咨询.
感谢和感谢.
推荐答案
我也面临着相同的问题,但是我不想单独使用Button和TextView,也不想使用Java代码来实现.所以我找到了.我知道我要晚解决.但这对您有帮助
I was also facing the same issue, But I don't want to use Button and TextView separately and also I don't want to make it using java code. So I found this. I know I am giving solution late. But it helps you
<FrameLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="20dp"
android:background="@drawable/next_btn_bg_rounded_corners">
<TextView
android:id="@+id/btn_restore_purchases"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@null"
android:drawableLeft="@mipmap/restore"
android:drawablePadding="10dp"
android:drawableStart="@mipmap/restore"
android:text="@string/restore_purchases"
android:textAllCaps="false"
android:textColor="@color/white" />
</FrameLayout>
这篇关于将文本视图内的可绘制图像对齐到中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!