应用在运行时在图像视图上显示黑色图像,而不是实际图像。

huangapple go评论80阅读模式
英文:

App shows black image on Image View instead of actual image at runtime

问题

ImageView在设置图像后变成了黑色。

我使用以下代码来设置图像

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Root = findViewById(R.id.Iv);

sensorManager = (SensorManager) getSystemService(Service.SENSOR_SERVICE);
Proximity = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);

//Root.setBackgroundColor(Color.MAGENTA);
Root.setImageResource(R.drawable.a);
}
英文:

The ImageView fills with black color after setting an image.

I'm setting image with this line

  super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Root = findViewById(R.id.Iv);

    sensorManager = (SensorManager) getSystemService(Service.SENSOR_SERVICE);
    Proximity = sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY);

    //Root.setBackgroundColor(Color.MAGENTA);
   Root.setImageResource(R.drawable.a);
}

Please Help!

答案1

得分: 0

请尝试以下内容:

    Context mContext = this;
    Root.setImageDrawable(mContext.getResources().getDrawable(R.drawable.a));
英文:

Please try with this

  Context mContext = this;
  Root.setImageDrawable(mContext.getResources().getDrawable(R.drawable.a));

答案2

得分: 0

由于移动屏幕具有不同的尺寸,因此您的图像分辨率可能较高,或者与 ImageView 的宽度和高度不兼容。尝试减小图像的尺寸,以便它可以在运行时加载。

英文:

As mobile screen comes with different sizes, so may be your image resolution is high or not compatible to the width & height of ImageView. Try to decrease the size of image so that it loads on Runtime also.

huangapple
  • 本文由 发表于 2020年8月23日 21:47:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/63547691.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定