简体   繁体   English

android-如何将imageview放在textview字母的顶部?

[英]android - how to put imageview on top of textview letter?

I've read an answer from this link 我已经从此链接中阅读了答案

but I want to add some icon on top of each textview 但我想在每个textview顶部添加一些图标

how to do that? 怎么做? any idea? 任何想法?

I've tried using layout_above , layout_below , etc but it's not what I wish 我尝试使用layout_abovelayout_below等,但这不是我想要的

Edited : 编辑:

the image size is big, how to set image size after add android:drawableTop="@drawable/image" 图片尺寸很大,添加android:drawableTop="@drawable/image"后如何设置图片尺寸

在此处输入图片说明

只需使用android:drawableTop="@drawable/YOUR_DRAWABLE"简单即可。

To set run time use code - 要设置运行时,请使用代码-

imgView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.imgSrc, 0, 0);

here (0, R.drawable.imgSrc, 0, 0) left-top-right-bottom 0 if you don't want to add. 如果不想添加,请在此处(0,R.drawable.imgSrc,0,0)左上右下0。

use this on your XML 在您的XML上使用它

android:drawableTop="@drawable/your_image"
android:drawablePadding="10dp"

or on you Activity class 或在您的活动课上

textView.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.your_image, 0, 0);
textView.setCompoundDrawablePadding(10);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM