为什么我的第一个应用程序没有显示在手机上?

时间:2019-10-26 09:33:01

标签: java android android-layout

我正在创建我的第一个hello word应用程序,第一个显示了一个hello word测试,并且可以在我的手机上使用,但是我在第二个应用程序中放了一张图片并运行它,电话显示:该应用程序已停止;我的应用程序完全按照我的意愿在xml设计上看! (我的手机装有android 7,而我使用android 4制作了该应用程序)

我尝试显示的图片具有3096x4128分辨率,但是当我尝试使用其他分辨率较低的图片时,我不知道这是否只是巧合!我试图更改应用程序的android,但存在相同的问题!

<ImageView 
android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
android:scaleType="centerCrop"
android:src="@drawable/hugo" />

<TextView 
android:text="What a Picture!" 
android:textSize="36sp"
android:fontFamily="sans-serif-light"
android:textColor="@android:color/white"
android:padding="20dp"
android:layout_width="wrap_content"
    android:layout_height="wrap_content" />

<TextView 
android:text="By AYMEN " 
android:layout_width="wrap_content"
    android:layout_height="wrap_content"
android:padding="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif-light"
android:textSize="36sp" />

2 个答案:

答案 0 :(得分:0)

您所使用的图像大小小于2MB。这是停止应用程序的主要原因。因此,请尝试调整其大小,然后在ImageView中使用它

答案 1 :(得分:0)

我认为您收到内存不足错误。为了避免这种情况,您可以使用Picasso或Glide库

implementation 'com.squareup.picasso:picasso:2.71828'

在Picasso中,您可以使用.fit()方法优化图像并将其加载到ImageView中,而不会降低图像质量。

Picasso  
    .with(context)
    .load(UsageExampleListViewAdapter.eatFoodyImages[0])
    .fit()
    // call .centerInside() or .centerCrop() to avoid a stretched image
    .into(imageViewFit);
相关问题