android - PNG 未显示在 ImageView 中

标签 android android-imageview

我有一个大的 .png 文件,我想在启动画面中显示它,但图像没有显示。 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"/>

以及 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);
}
}

这样,图像就不会显示了。我试过在 xml 中使用 android:src:,但它不起作用。

图片很大。在将它放入 ImageView 之前我需要调整它的大小吗?如果不是,为什么图像不显示?

谢谢。

编辑:PNG 为 1080x1920

最佳答案

在我的例子中,我使用的是文件名为“go-back-filename.png”的图像。 xml文件就像

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

在我将文件名更改为“go_back_icon”后,它工作正常。 希望这对某人有帮助。

关于android - PNG 未显示在 ImageView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32091386/

相关文章:

Android Bitmap.getPixel 总是返回负数

Android:对文本后的图像使用 alignBaseline

android - Cordova InAppBrowser 并与 webview 共享 cookie

java - 无法从 Activity 中调用 RecyclerView 适配器的方法

自定义 View 中的 Android 动画矩形

android - 如何渲染从 onPreExecute() 中的 AsyncTask 获取的 ArrayList<ImageView>?

Android Camera Intent 与 Android L 崩溃

android - Google 语音识别器无法在 Android 4.x 上启动

android - 如何将参数从 Activity 传递到服务......当用户停止服务时

android - 如何在android中的网格中显示图像?