【问题标题】:android - how to put imageview on top of textview letter?android - 如何将 imageview 放在 textview 字母之上?
【发布时间】:2017-11-14 00:08:20
【问题描述】:

我读过an answer from this link

但我想在每个文本视图的顶部添加一些图标

怎么做?有什么想法吗?

我尝试过使用layout_abovelayout_below 等,但这不是我想要的

编辑:

图片很大,添加android:drawableTop="@drawable/image"后如何设置图片大小

【问题讨论】:

    标签: android textview


    【解决方案1】:

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

    【讨论】:

    • drawable 中银的代码是什么? EDIT 有什么方法可以设置图片/图标的大小吗?还是我应该调整图像大小?
    【解决方案2】:

    设置运行时使用代码 -

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

    这里 (0, R.drawable.imgSrc, 0, 0) 左上右下 0 如果你不想添加。

    【讨论】:

      【解决方案3】:

      在你的 XML 上使用它

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

      或者你的Activity类

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

      【讨论】:

      • 有办法设置图片大小吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多