ImageView,你如何以编程方式获得可绘制的Src?

时间:2014-11-18 02:30:27

标签: android imageview drawable src

因此对于ImageView,有一个返回背景drawable的imageView.getBackground()。有没有办法像这样以编程方式获取src drawable?

以下是我的意思的一个小例子:

main.xml的片段

...
<ImageView
    android:id="@+id/main_iv"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:src="@drawable/imageSrc"
    android:background="@drawable/imageBG" />
...

爪哇

public class ActivityMain extends Activity {
    ImageView iv;
    ...

    ...
    @Override
    public void onCreate(Bundle sIS){
        super.onCreate(sIS);
        setContentView(R.layout.main);
        iv = (ImageView)findViewById(R.id.main_iv);
        Drawable bg = iv.getBackground();
        // Drawable source = iv.getSource(); but this method does not exist
    }
...
}

1 个答案:

答案 0 :(得分:4)

Call getDrawable()获取Drawable中的ImageView