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

12,717

Solution 1

You should use setImageResource not setBackgroundResource.

Solution 2

Use this:

view.setImageResource(R.drawable.np);
Share:
12,717

Related videos on Youtube

ali shekari
Author by

ali shekari

Updated on August 27, 2022

Comments

  • ali shekari
    ali shekari over 1 year

    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!