Android - ImageView blank (xml only)
Android - ImageView blank (xml only)
I am having a weird issue on my new project, I just cant display an image on my activity.
The ImageView shows a blank square.
screenshot
If I try with a black background and a picture with transparency, I can see the picture that appears in white even if it is supposed to be colored.
But if I try with a multi colored picture with no transparency, it just shows a blank square.
I tried on emulator and phone with the exact same result.
I checked all the related posts on Stackoverflow without any working solution.
My src :
I added a small picture in res/drawable/test2.png
Here is my (very basic) activity code / activity_main.xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/test2"
/>
</LinearLayout>
My Activity :
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Manifest:
<application
android:name=".Application"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".activity.MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
And my build file:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
buildToolsVersion "27.0.3"
defaultConfig {
applicationId "com.test.myappid"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:27.1.1'
compile 'com.android.support:design:27.1.1'
compile 'com.evernote:android-job:1.2.4'
compile 'com.android.volley:volley:1.1.0'
testCompile 'junit:junit:4.12'
androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
}
Thanks for your help !
test2.png
Exactly try with other picture
– Rohit Sharma
2 days ago
@HongDuan I tried with maybe 10 different pictures, different formats (jpg, bmp, mostly png) with transparency or not. Always the same: everything that is not transparent is blank. I just tried with this pic (shareicon.net/data/256x256/2016/09/16/829667_nature_512x512.png) and I get a blank circle
– Quetzalcoatl
2 days ago
There must be some hidden differences in your project, you'd better share a complete project which can reproduce this issue, you can publish it to you github so we can help you.
– Hong Duan
2 days ago
@HongDuan I solved the issue, see my comment below. Thank you for your time !
– Quetzalcoatl
2 days ago
3 Answers
3
Can you try using
android:scaleType:"centreInside"
to see if this is a scaling issue? Also, what is the dimens of the image?
Added android:scaleType="centerInside" on the ImageView but still blank
– Quetzalcoatl
2 days ago
did you check the dimens and size of the image?
– Yogesh Madaan
2 days ago
I would use glide to manage pictures honestly! It's gonna be easier in the long run to manage picture that way!
https://github.com/bumptech/glide
Also make sure that you set the following code for a cache optimization
@Override public void applyOptions(Context context, GlideBuilder builder) {
builder.setMemoryCache(new MemoryCacheAdapter());
}
Doesnt really solve the issue but it looks very interesting, i might use it in the future
– Quetzalcoatl
2 days ago
Ok my bad I just failed at copy / paste.
I had this in my style.xml:
<item name="android:tint">@color/colorLight</item>
Removing it fixed the issue.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
share your
test2.png
– Hong Duan
2 days ago