【问题标题】:How to set an image's width and height when it's set in drawableLeft在drawableLeft中设置图像时如何设置图像的宽度和高度
【发布时间】:2015-12-17 09:05:45
【问题描述】:

我将图像设置为 RadioButton 的 drawableLeft,但它太大了。我想设置图像的高度、宽度和 scaleType 以让它看起来不错,就像在 ImageView 中一样:

android:layout_width="30dip"
android:layout_height="30dip"
android:scaleType="fitXY"

但我发现在 drawableLeft 中设置图像时没有属性。

有没有办法解决这个问题。

是否可以在 XML 中处理?

【问题讨论】:

  • 你想改变单选按钮或图片的高度?
  • 你也可以使用drawable padding属性。
  • @Abhishek 我只想更改图像的大小,而不是单选按钮。
  • @EyadMhanna drawable padding 可以改变大小。

标签: android android-drawable android-radiobutton


【解决方案1】:

我认为这应该可行:

Drawable drawable = context.getResources().getDrawable(id);
drawable.setBounds(0, 0, 30, 30);
radioButton.setCompoundDrawables(drawable, null, null, null);

【讨论】:

  • @L.Swifter 为此,您必须创建自己的自定义视图.. Go to this link
【解决方案2】:

AFAIK,您不会在drawableLeft 中获得ImageView 的所有比例。 为此,您必须将FrameLayoutRelativeLayoutImageViewRadioButton 一起使用

您可以使用android:drawablePadding 在文本和可绘制对象之间进行填充

【讨论】:

  • 你的意思是没有 ViewGroup 就没有办法解决这个问题?
猜你喜欢
  • 2012-03-01
  • 2014-06-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-09-05
  • 2019-01-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多