java - 为什么我的第一个应用程序没有出现在我的手机上?

标签 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" />

最佳答案

我认为您遇到了 OutOfMemory 错误。为避免这种情况,您可以使用 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);

关于java - 为什么我的第一个应用程序没有出现在我的手机上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58569600/

相关文章:

android - 更改 Volley 框架的重定向策略

android - 如何知道在jetpack compose的惰性行的视口(viewport)中完全可见的项目?

java - 左上角有两条丝带的图像

java - Disqus 单点登录 (SSO) 问题

java - JUnit + Maven : accessing ${project. build.directory} 值

java - 将 int 转为 Short 的简单位操作

Android约束布局包括另一个布局

java - 在插入 BST 期间获取实际索引

java - 安卓中的布局

离线时 Android 缓存只读 REST API 响应