gpt4 book ai didi

java - 滚动时图像滞后如何解决?

转载 作者:行者123 更新时间:2023-11-29 20:21:23 25 4
gpt4 key购买 nike

我在 tab1 相对布局中使用 android studio 创建了一个应用程序我有 8 张图像但是当我运行我的应用程序并滚动时它滞后如何修复滚动时滞后。

这是代码

package com.example.drh3cker.ihebski_swip;


import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.PagerTabStrip;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

//this project developped by iheb ben salem@IBSSoft
public class MainActivity extends FragmentActivity {

ViewPager pager;
PagerTabStrip tab_strp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_tab);
ma_pager_adapter mapager=new ma_pager_adapter(getSupportFragmentManager());
pager=(ViewPager)findViewById(R.id.pager);

pager.setAdapter(mapager);
tab_strp=(PagerTabStrip)findViewById(R.id.tab_strip);
tab_strp.setTextColor(Color.WHITE);
// tab_strp.setTextSize(14,14);
// tab_strp.setTabIndicatorColor(Color.WHITE);
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.share) {
return true;
}

return super.onOptionsItemSelected(item);
}


public void browser1(View view) {
Intent browserIntent=new Intent(Intent.ACTION_VIEW, Uri.parse("http://example.com"));
startActivity(browserIntent);

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:weightSum="1">

<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">


<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/imageView"
android:src="@drawable/fra"
android:background="#f44437"
android:contentDescription="@string/App_Title_Image" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="150dp"
android:id="@+id/imageView2"
android:src="@drawable/saavnmusicapp"
android:paddingTop="8sp"
android:onClick="browser1"
android:contentDescription="@string/saavn_music_app"
android:scaleType="fitCenter"
android:layout_below="@+id/imageView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
style="?android:borderlessButtonStyle"/>

<ImageView
android:layout_width="wrap_content"
android:layout_height="150dp"
android:id="@+id/imageView3"
android:src="@drawable/earntalktime"
android:layout_below="@+id/imageView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:contentDescription="@string/earn_talktime_image"
android:onClick="browser2"
style="?android:borderlessButtonStyle"/>

<ImageView
android:layout_width="wrap_content"
android:layout_height="150dp"
android:id="@+id/imageView4"
android:src="@drawable/flipkart"
android:onClick="browser3"
android:contentDescription="@string/flipkart_app_image"
android:layout_below="@+id/imageView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
style="?android:borderlessButtonStyle"/>

<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:id="@+id/imageView5"
android:layout_below="@+id/imageView4"
android:layout_centerHorizontal="true"
android:src="@drawable/paytmapp"
android:contentDescription="@string/paytm_app_image"
android:onClick="browser4"
style="?android:borderlessButtonStyle"/>

<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:id="@+id/imageView6"
android:layout_below="@+id/imageView5"
android:layout_centerHorizontal="true"
android:src="@drawable/uc"
android:onClick="browser5"
style="?android:borderlessButtonStyle"
android:contentDescription="@string/uc_browser_image" />

<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:id="@+id/imageView7"
android:layout_below="@+id/imageView6"
android:layout_centerHorizontal="true"
android:src="@drawable/dailyhunt"
android:onClick="browser6"
style="?android:borderlessButtonStyle"
android:contentDescription="@string/uc_browser_image" />

<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:id="@+id/imageView8"
android:layout_below="@+id/imageView7"
android:layout_centerHorizontal="true"
android:src="@drawable/freepaisa"
android:onClick="browser7"
style="?android:borderlessButtonStyle"
android:contentDescription="@string/uc_browser_image" />

<ImageView
android:layout_width="match_parent"
android:layout_height="150dp"
android:id="@+id/imageView9"
android:layout_below="@+id/imageView8"
android:layout_centerHorizontal="true"
android:src="@drawable/mobikwik"
android:onClick="browser8"
style="?android:borderlessButtonStyle"
android:contentDescription="@string/uc_browser_image" />




</RelativeLayout>
</ScrollView>

Stackoverflow 告诉我添加更多详细信息我不知道为什么我添加了问题和代码,我想知道我该如何解决,任何人都可以帮助我

谢谢。

最佳答案

在 ImageView 中加载图像时使用

imageview.setImageBitmap(BitmapFactory.decodeResource(getContext().getResources(), R.drawable.image);

imageview.setImageResource(R.drawable.image);

根据我的经验,它减少了 Java 和图形的内存消耗高达 89%,这使得应用程序运行更流畅,使用的内存更少,因此,在您的应用程序运行时进行的垃圾收集更少。

接下来,对图像的文件大小设置限制以确保尽可能高的性能

From:      image.jpg    |    1.2MB

To:          image.jpg    |    512KB

当文件已经在您的资源文件夹中时,您可以在 Mac 中“在 Finder 中显示”或在 Windows 中“在资源管理器中打开”以显示您的文件,然后您可以...

  • 在 Mac 预览中调整图像大小
  • 使用 Microsoft Office Picture Manager 在 Windows 中调整图像大小或调整图像文件大小(即使在今天仍然有帮助)

最后,也许您会发现这篇文章对您的问题有帮助

https://medium.freecodecamp.org/how-we-reduced-memory-footprint-by-50-in-our-android-app-49efa5c93ad8

关于java - 滚动时图像滞后如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33124850/

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