setScaleType to ScaleType.MATRIX programmatically not work but in xml it work

你离开我真会死。 提交于 2019-12-21 09:24:06

问题


this is my code :

    LinearLayout imageViewParent = (LinearLayout) findViewById(R.id.imageViewParent);
    ImageView view = new ImageView(this);
    imageViewParent.addView(view);
    view.setScaleType(ScaleType.MATRIX);
    view.setBackgroundResource(R.drawable.np);

In this code scale type to matrix not work(it fix image to parents),but when I implement this in xml it works fine! can every one help me? thank you!


回答1:


You should use setImageResource not setBackgroundResource.




回答2:


Use this:

view.setImageResource(R.drawable.np);


来源:https://stackoverflow.com/questions/18952656/setscaletype-to-scaletype-matrix-programmatically-not-work-but-in-xml-it-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!