Time delay when switching Android screens

Asked 1 years ago, Updated 1 years ago, 111 views

Loading the main screen (1.5 seconds) when running the app or switching the screen feels a little slow.

Put the image in the layout background as shown in the code below

There are also two images in the fragment.

I looked it up and it seems that the capacity of the image file is reduced using bitmap.

If I switch to a bitmap, should I attach an image directly to the view in Java code instead of @drawable in xml?

<?xml version="1.0" encoding="utf-8"?>
<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:background="@drawable/intro"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.candle.xxxxx.MainActivity">

    <ImageView
        android:id="@+id/btn_intro"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="110dp"
        android:src="@drawable/btn_intro" />

    <FrameLayout
        android:id="@+id/fragment_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true" />

</RelativeLayout>

imageview drawable android

2022-09-21 18:11

1 Answers

I think you're talking about dynamic image loading. Dynamic loading of images provides an advantage in that part because there is no image loading at the first turn on.

However, the portion may look empty until the image is read. In this case, there may be a way to show a small image while loading or to make it look not empty by laying the appropriate background color.

There is also a way to dynamically show the drawables as shown below.

Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable. btn_intro);
((ImageView) findViewById(R.id. btn_intro)).setImageBitmap(bitmap);

You can also import it through an input stream.

InputStream inputStream  = new ByteArrayInputStream(decoded);
Bitmap bitmap  = BitmapFactory.decodeStream(inputStream);
((ImageView) findViewById(R.id. btn_intro)).setImageBitmap(bitmap);

Recently, external libraries are often used to process them. Please refer to the following two libraries.


2022-09-21 18:11

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.