Search code examples
androidandroid-imageview

PNG not showing in ImageView


I have a large .png and i want to show it in a Splash screen, but the image is not showing. The xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.infaplic.lpi.activities.SplashActivity">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/imageView2"/>

And the code of the Activity:

public class SplashActivity extends Activity {

ImageView imagen;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    imagen=(ImageView)findViewById(R.id.imageView2);
    imagen.setImageDrawable(getResources().getDrawable(R.drawable.pantalla_arranque));
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {

            Intent mainIntent = new Intent(SplashActivity.this, NextActivity.class);
            SplashActivity.this.startActivity(mainIntent);
            SplashActivity.this.finish();
        }
    }, 1000);
}
}

This way, the image is not showing. I have tried with android:src: in the xml, but it doesn't work.

The image is very large. Do I need to resize it before putting it in the ImageView? If not, why is the image not showing?

Thank you.

EDIT: The PNG is 1080x1920


Solution

  • Since you write that your image is very large I would guess it is too large. I have a bug in one of my apps there I generate an image which is bigger then 2048 pixels. Some devices does not support such big images I would guess that you run into a similar problem.

    If that is some background image reduce the image size, a background image is not so important that each pixel on the screen has to own a image pixel.