gpt4 book ai didi

android - 花时间在android中加载背景图片

转载 作者:行者123 更新时间:2023-11-30 01:08:48 25 4
gpt4 key购买 nike

我正在使用 Picasso 加载背景图像,并且我正在使用相对布局。背景图像需要时间来加载,有些甚至没有加载。我的一段代码是,

        final int k = random.nextInt(20);
ImageView imageView= (ImageView)findViewById(R.id.backgrd);
TypedArray imgb = getResources().obtainTypedArray(R.array.backg);
int resourceId = imgb.getResourceId(k, 0);

Picasso.with(getApplicationContext()).
load(resourceId).
fit().
noPlaceholder().
into(imageView);

我尝试使用 resize() Picasso Taking time to load images也,但它不工作。

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relative1"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">


<ImageView
android:id="@+id/backgrd"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
/>

<ImageView
android:id="@+id/img1"
android:paddingTop="90dp"
android:layout_width="wrap_content"
android:layout_height="400dp"
/>

最佳答案

检查您用于加载的可绘制图像的大小和分辨率。

xlarge screens are at least 960dp x 720dp
large screens are at least 640dp x 480dp
normal screens are at least 470dp x 320dp
small screens are at least 426dp x 320dp
Generalised Dpi values for screens:

ldpi Resources for low-density (ldpi) screens (~120dpi)
mdpi Resources for medium-density (mdpi) screens (~160dpi). (This is the baseline density.)
hdpi Resources for high-density (hdpi) screens (~240dpi).
xhdpi Resources for extra high-density (xhdpi) screens (~320dpi).
Therefore generalised size of your resources (assuming they are full screen):

ldpi
Vertical = 426 * 120 / 160 = 319.5px
Horizontal = 320 * 120 / 160 = 240px
mdpi
Vertical = 470 * 160 / 160 = 470px
Horizontal = 320 * 160 / 160 = 320px
hdpi
Vertical = 640 * 240 / 160 = 960px
Horizontal = 480 * 240 / 160 = 720px
xhdpi
Vertical = 960 * 320 / 160 = 1920px
Horizontal = 720 * 320 / 160 = 1440px

px = dp*dpi/160

https://stackoverflow.com/a/16352208/5567283

关于android - 花时间在android中加载背景图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38627653/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com