英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论