Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 313
Fustigador Avatar asked Nov 27 '22 01:11

Fustigador


1 Answers

In my case I was using a image with file name like "go-back-filename.png". And xml file is like

 <ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/go-back-icon"/>

After i changed the file name to "go_back_icon" it worked fine. Hope this helps someone.

like image 199
Ajay Naredla Avatar answered Dec 24 '22 11:12

Ajay Naredla