首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >我的活动很慢,有6个ImageViews和CardViews。如何压缩或降低图像质量/大小?

我的活动很慢,有6个ImageViews和CardViews。如何压缩或降低图像质量/大小?
EN

Stack Overflow用户
提问于 2018-01-11 12:36:25
回答 3查看 57关注 0票数 0

我在Android上有一个活动,它真的很慢。它有6个ImageViews,所以我猜是他们造成的。我该如何处理它们呢?我是否要压缩它们,降低它们的质量,以及我如何准确地实现这一点?是不是CardViews导致了运行迟缓?我是否应该压缩来自外部工具的图像,以及我应该将它们设置为多大?另外,有没有内置的函数来实现这一点呢?

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:background="#006064"
    android:layout_height="match_parent">

    <LinearLayout

        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="10dp"
        android:id="@+id/ll"
        android:weightSum="1"
        android:layout_marginTop="-10dp"
        >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:clipToPadding="false"
            android:onClick="goToChild"
            android:gravity="center"
            android:orientation="horizontal">

            <android.support.v7.widget.CardView
                android:layout_width="160dp"
                android:layout_height="190dp"
                android:layout_margin="10dp"
                android:clickable="true"
                android:onClick="goToDash"
                android:foreground="?android:attr/selectableItemBackground">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="181dp"
                    android:gravity="center"
                    android:orientation="vertical"
                    android:weightSum="1">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="70dp"
                        android:layout_weight="1.02"
                        android:background="#B2FF59"
                        android:padding="10dp"
                        android:src="@drawable/dash2"
                        android:onClick="goToChild"
                        />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:text="DASHBOARD"
                        android:textStyle="bold" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:layout_margin="10dp"
                        android:background="@color/lightgray" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:padding="5dp"
                        android:text="Open the Dashboard"
                        android:textColor="@android:color/darker_gray"
                        android:textSize="14sp" />

                </LinearLayout>
            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView
                android:layout_width="160dp"
                android:layout_height="190dp"
                android:layout_margin="10dp"
                android:clickable="true"
                android:onClick="goToSpy"
                android:foreground="?android:attr/selectableItemBackground">

                <LinearLayout
                    android:id="@+id/routeOption"
                    android:layout_width="match_parent"
                    android:layout_height="180dp"
                    android:gravity="center"
                    android:orientation="vertical"
                    android:weightSum="1">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="64dp"
                        android:layout_weight="1.07"
                        android:background="#448AFF"
                        android:padding="10dp"
                        android:src="@drawable/docico" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:text="MY DOCUMENTS"
                        android:textStyle="bold" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:layout_margin="10dp"
                        android:background="@color/lightgray" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:padding="5dp"
                        android:text="Save documents"
                        android:textColor="@android:color/darker_gray"
                        android:textSize="14sp" />

                </LinearLayout>
            </android.support.v7.widget.CardView>

        </LinearLayout>

        <LinearLayout

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.1"
            android:clipToPadding="false"
            android:gravity="center"
            android:orientation="horizontal">

            <android.support.v7.widget.CardView
                android:layout_width="160dp"
                android:layout_height="190dp"
                android:layout_margin="10dp"
                android:clickable="true"
                android:onClick="goToPlanner"
                android:foreground="?android:attr/selectableItemBackground">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:id="@+id/plannerOption"
                    android:orientation="vertical"
                    android:weightSum="1">

                    <ImageView
                        android:id="@+id/imageView5"
                        android:layout_width="207dp"
                        android:layout_height="70dp"
                        android:layout_weight="1.02"
                        android:background="#F44336"
                        android:padding="10dp"
                        android:src="@drawable/plannerico" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:text="PLANNER"
                        android:textStyle="bold" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:layout_margin="10dp"
                        android:background="@color/lightgray" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:padding="5dp"
                        android:text="Set your Plans!"
                        android:layout_marginBottom="1dp"
                        android:textColor="@android:color/darker_gray"
                        android:textSize="14sp" />

                </LinearLayout>
            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView
                android:layout_width="160dp"
                android:layout_height="190dp"
                android:layout_margin="10dp"
                android:clickable="true"
                android:onClick="goToPlanner"
                android:foreground="?android:attr/selectableItemBackground">

                <LinearLayout
                    android:id="@+id/taskOption"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:gravity="center"
                    android:orientation="vertical"
                    android:weightSum="1">

                    <ImageView
                        android:id="@+id/imageView"
                        android:layout_width="207dp"
                        android:layout_height="57dp"
                        android:layout_weight="1.02"
                        android:background="#FFEB3B"
                        android:padding="10dp"
                        android:src="@drawable/tasks2" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:text="TASKS"
                        android:textStyle="bold" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:layout_margin="10dp"
                        android:background="@color/lightgray" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:padding="5dp"
                        android:text="Tasks by Company"
                        android:layout_marginBottom="1dp"
                        android:textColor="@android:color/darker_gray"
                        android:textSize="14sp" />

                </LinearLayout>
            </android.support.v7.widget.CardView>



        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:clipToPadding="false"
            android:onClick="goToSummary"
            android:gravity="center"
            android:orientation="horizontal">

            <android.support.v7.widget.CardView
                android:layout_width="160dp"
                android:layout_height="190dp"
                android:layout_margin="10dp"
                android:clickable="true"
                android:onClick="goToSummary"
                android:foreground="?android:attr/selectableItemBackground">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="181dp"
                    android:gravity="center"
                    android:orientation="vertical"
                    android:weightSum="1">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="64dp"
                        android:layout_weight="1.02"
                        android:background="#FFEB3B"
                        android:padding="10dp"
                        android:src="@drawable/remico"
                        android:onClick="goToChild"
                        />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:text="REMARKS"
                        android:textStyle="bold" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:layout_margin="10dp"
                        android:background="@color/lightgray" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:padding="5dp"
                        android:text="Company's Remarks"
                        android:textColor="@android:color/darker_gray"
                        android:textSize="14sp" />

                </LinearLayout>
            </android.support.v7.widget.CardView>

            <android.support.v7.widget.CardView
                android:layout_width="160dp"
                android:layout_height="190dp"
                android:layout_margin="10dp"
                android:clickable="true"
                android:onClick="goToSettings"
                android:foreground="?android:attr/selectableItemBackground">

                <LinearLayout
                    android:id="@+id/setting"
                    android:layout_width="match_parent"
                    android:layout_height="180dp"
                    android:gravity="center"
                    android:orientation="vertical"
                    android:weightSum="1">

                    <ImageView
                        android:id="@+id/imageView2"
                        android:layout_width="match_parent"
                        android:layout_height="64dp"
                        android:layout_weight="1.07"
                        android:background="#B2FF59"
                        android:padding="10dp"
                        android:src="@drawable/meetico" />

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="10dp"
                        android:text="MEETING MINUTES"
                        android:textStyle="bold" />

                    <View
                        android:layout_width="match_parent"
                        android:layout_height="1dp"
                        android:layout_margin="10dp"
                        android:background="@color/lightgray" />

                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:padding="5dp"
                        android:text="Meetings Summary"
                        android:textColor="@android:color/darker_gray"
                        android:textSize="14sp" />

                </LinearLayout>
            </android.support.v7.widget.CardView>

        </LinearLayout>

    </LinearLayout>

</ScrollView>
EN

回答 3

Stack Overflow用户

发布于 2018-01-11 12:49:20

根据我在你的问题中看到的和提供的信息:

如果图片是资源(放在可绘制的文件夹中),你应该使用足够大的屏幕尺寸和分辨率的phone/tablet/etc.

  • You可以让安卓压缩图像,但如果你压缩它们会更好,如果你使用一个程序,如photoshop,gimp,甚至微软的
  • 编辑器,甚至MS Word。
票数 0
EN

Stack Overflow用户

发布于 2018-01-11 13:13:26

有几种方法可以减少“懒惰”。

  • 确保您的图像在密度特定的文件夹中以不同的密度可用。我喜欢使用最终的安卓大小调整程序(在线查找.jar )来轻松地将我的图像调整到合适的密度文件夹中。
  • 通过ImageOptim或tinyPNG
  • 等压缩工具运行您的图像,使用Glide或毕加索等图像加载库将图像资源加载到您的android Lint中您的代码中,并在性能问题下查找更多线索
票数 0
EN

Stack Overflow用户

发布于 2018-01-11 14:05:34

尝试使用Picasso库:

添加依赖项compile 'com.squareup.picasso:picasso:2.5.2'

  • then

ImageView imageView=findViewById(R.id.imageView); Picasso.with(context).load(R.drawable.myimage).fit(). centerCrop().into(imageView);

确保在加载到ImageView之前使用fit()调整图像的大小。否则,如果渲染大量图片,您将消耗额外的内存、遇到滚动缓慢或遇到内存不足问题。

有关毕加索的更多信息,请参阅此link

导致应用程序缓慢的原因是将如此大的图像加载到内存中,因为您使用的是大图像尺寸,毕加索会调整和缓存图像的大小。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48207261

复制
相关文章
oracle中number的用法,Oracle Number数字
在本教程中,您将学习Oracle NUMBER数据类型以及如何使用它来为表定义数字列。
全栈程序员站长
2022/09/15
1.7K0
Flutter 中FlatButton的替代方案
最新版本的Flutter已将FlatButton标记为过时,我们可以使用 TextButton 或 ElevatedButton 来进行替代,FlatButton 与替代组件的参数会有差异。
xiangzhihong
2023/07/09
6610
oracle number整数,Oracle number类型的语法和用法
1. 精度(precision),或总位数。默认情况下,精度为38位,取值范围是1~38之间。也可以用字符*表示38。
全栈程序员站长
2022/09/15
2.5K0
oracle的number类型
p : 精度位precision,数据的有效位;取值范围38;默认38;*表示38
全栈程序员站长
2022/09/15
6550
Electron中remote模块的替代方案
在Electron12时候被废弃,使用必须配置enableRemoteModule
码客说
2023/09/14
2K0
Oracle中number数据类型的存储机制
Oracle中number数据类型存储的是整型,碰巧看到这篇文章讲解了通过分析索引了解0和1的存储机制,值得学习一下。
bisal
2023/01/13
9970
Java中的大量if else语句的替代方案
之前写过转载过一篇类似的不错的文章《除代码中的 if-else/switch-case的正确姿势》https://blog.csdn.net/w605283073/article/details/89117561,
明明如月学长
2021/08/31
1.8K0
Linux 中 cron 系统的 4 种替代方案
cron 适用于长期重复任务。如果你设置了一个工作任务,它会从现在开始定期运行,直到计算机报废为止。但有些情况下你可能只想设置一个一次性命令,以备不在计算机旁时该命令可以自动运行。这时你可以选择使用 at 命令。
用户1880875
2021/09/07
2.5K0
Base:Acid的替代方案
作者:DAN PRITCHETT 译者:java达人 来源:https://queue.acm.org/detail.cfm?id=1394128(点击阅读原文前往) 在数据库分区中,以一致性换取可
java达人
2018/03/26
2.3K0
Base:Acid的替代方案
Web 框架的替代方案
在本系列第二部分中,Noam 提出了一些模式,说明如何直接用 Web 平台作为框架提供的一些解决方案的替代方案。
深度学习与Python
2022/04/19
2.6K0
Hugo .GitInfo 的替代方案
今天有人问我博客页脚 footer 里的 git hash 是怎么显示的,就是页面底部里的 69d6ffe 这一串数字。
eallion
2022/12/20
1.9K0
Hugo .GitInfo 的替代方案
如何将SQLServer2005中的数据同步到Oracle中
有时由于项目开发的需要,必须将SQLServer2005中的某些表同步到Oracle数据库中,由其他其他系统来读取这些数据。不同数据库类型之间的数据同步我们可以使用链接服务器和SQLAgent来实现。假设我们这边(SQLServer2005)有一个合同管理系统,其中有表contract 和contract_project是需要同步到一个MIS系统中的(Oracle9i)那么,我们可以按照以下几步实现数据库的同步。
深蓝studyzy
2022/06/16
3K0
oracle number数据类型的精度
p: 1—38 s: -84—127 a、s > 0 (精确到小数点右边 s 位,并四舍五入 。然后检验有效数位是否 <= p) 例如:number(5,2) 有效数字最多是5位,保留小数点后2位; 123.45 — 123.45 123 — 123.00 1.2356 — 1.24 0.001 — 0.00 b、s < 0 (精确到小数点左边 s 位,并四舍五入 。然后检验有效数位是否 <= p + |s|) 例如:number(5,-2) 小数点左边最后2位四舍五入,最多7位有效数字 123456 — 123460 1234567.6789 — 1234600 1 — 0 总结:在 p < s 这种情况下 只能用来存放大于0小于1的小数。 在 p > s 这种情况下 小数点前最多只能插入:p – s个数字,但小数点后的数字可以是任意长度(保存时会四舍五入)
全栈程序员站长
2022/09/15
1.3K0
Oracle number类型的语法和用法
摘要:先根据精度值,对number类型的数据从左边第一个非零数字开始数精度值个位数,之后的位数截断不要(要四舍五入吗),再根据小数位置值,对number类型的数据右边的低位进行四舍五入(如果小数位置值为负的,如何处理?)
全栈程序员站长
2022/09/15
2.3K0
CentOS 8/6 Linux 生命终结,2022 年最好的替代方案是什么?
◆ 前言 Red Hat 最近宣布,CentOS 8 Linux将不再支持并在 2021 年底停止使用。取而代之的是滚动版本 CentOS Stream 作为 RHEL 的下游分支于 2019 年推出,将持续排查漏洞,让上游版本更加稳定和安全。 但是,运行 CentOS 7 的服务器不会受到影响。他们将与 RHEL 7 生命周期并行更新。RHEL 7 将在 2024 年结束其最后一个维护周期。 但是,如果您使用的是 CentOS 8,那么 2022 年有哪些替代方案?不幸的是,即使您找到了,服务器应用程序的
IT大咖说
2022/03/08
6.4K0
oracle number转为timestamp timestamp转number
现在平台有个字段是用来记录插入时间的,但是是用number型存储,想转为时间类型的。 结果: SELECT TO_CHAR(字段名 / (1000 * 60 * 60 * 24) + TO_DATE(‘1970-01-01 08:00:00’, ‘YYYY-MM-DD HH24:MI:SS’), ‘YYYY-MM-DD HH24:MI:SS’) AS CDATE FROM 表名; 解决问题的过程: http://blog.csdn.net/a9529lty/article/details/5306622
全栈程序员站长
2022/09/15
2.1K0
Oracle number数据类型的使用[通俗易懂]
第一种情况: number后面都是两个正数,第一个数表示有效位,第二个数表示小数点后的位数(也就是精确度,需要进行四舍五入) 例如
全栈程序员站长
2022/09/15
6040
点击加载更多

相似问题

Spring数据-@修改(clearAutomatically= true,flushAutomatically = true)导致另一个实体不被更新

11

我可以在接口上使用spring注解吗?

14

调试时,我可以“跳过”jQuery代码吗?

51

我可以将注解注入pojo吗?

11

使用Kwargs时,我可以在Python中跳过参数吗?

21
添加站长 进交流群

领取专属 10元无门槛券

AI混元助手 在线答疑

扫码加入开发者社群
关注 腾讯云开发者公众号

洞察 腾讯核心技术

剖析业界实践案例

扫码关注腾讯云开发者公众号
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文