我开发了一个应用程序,它从 json 检索数据到移动设备上的本地数据库,并使用 RecyclerView 从本地数据库显示它,我的容器布局如下所示:
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="end"
android:layout_gravity="end"
android:id="@+id/detailContainerLayout"
android:baselineAligned="true"
android:background="@drawable/border_bottom"
>
<TextView
android:id="@+id/article_title"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="220dp"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingTop="2dp"
android:layout_marginRight="9dp"
android:layout_marginLeft="4dp"
android:textColor="@color/buttons_background"
android:fontFamily="sans-serif-condensed"
android:maxLines="2"
android:textSize="@dimen/text_main"
android:layout_gravity="end"
android:gravity="start"
android:layoutDirection="rtl"/>
<TextView
android:id="@+id/article_date"
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="9dp"
android:textColor="@color/textColor"
android:maxLines="1"
android:layout_gravity="end"
android:gravity="end"
android:textSize="@dimen/date_size"
android:layout_marginTop="8dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_gravity="center_horizontal|bottom"
android:gravity="center_horizontal|bottom"
android:layout_marginTop="10dp"
>
<TextView
android:id="@+id/article_place"
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/textColor"
android:layout_gravity="start|bottom"
android:gravity="start|bottom"
android:layout_weight="1.1"
android:maxLines="1"
android:fontFamily="sans-serif"
android:paddingBottom="5dp"
android:layoutDirection="rtl"
android:layout_marginRight="3dp"
/>
<TextView
android:id="@+id/article_placeIcon"
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/textColor"
android:maxLines="1"
android:layout_gravity="start|bottom"
android:gravity="start|bottom"
/>
<TextView
android:id="@+id/article_subtitle"
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/textColor"
android:maxLines="1"
android:layout_gravity="start|bottom"
android:gravity="start|bottom"
android:layout_weight="1.4"
android:fontFamily="sans-serif"
android:layout_marginRight="3dp"
android:paddingBottom="5dp"
android:layoutDirection="rtl"
/>
<TextView
android:id="@+id/article_subtitleICON"
style="@style/TextAppearance.AppCompat.Body1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/textColor"
android:maxLines="1"
android:layout_gravity="start|bottom"
android:gravity="start|bottom"
android:fontFamily="sans-serif"
android:layout_marginRight="9dp"
android:paddingBottom="5dp"
android:layoutDirection="rtl"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="80dp"
android:gravity="start|bottom"
android:layout_gravity="start|bottom"
>
<elryad.harajsooq.ActionbarContent.AllAds.ui.DynamicHeightNetworkImageView
android:id="@+id/thumbnail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/photo_placeholder"
android:layout_gravity="start|bottom"
/>
</LinearLayout>
所以当我使用 CardView 或 RelativeLayout 作为我的项目的容器时,它们使我的应用程序缓存和内存使用率非常高,我的 DATA是 20MB,我的 CACHE 是 50MB+,但是在我将容器布局更改为 ConstraintLayout
<android.support.constraint.ConstraintLayout 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:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:clickable="true"
android:focusable="true"
android:background="@drawable/border_bottom">
<TextView
android:id="@+id/article_title"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginRight="5dp"
android:layout_marginTop="-10dp"
android:gravity="right"
android:fontFamily="sans-serif-condensed"
android:maxLines="1"
android:paddingLeft="5dp"
android:paddingTop="2dp"
android:textColor="@color/buttons_background"
android:textSize="@dimen/text_main"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toRightOf="@+id/thumbLayout"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<items ....
....>
</android.support.constraint.ConstraintLayout>
数据和缓存恢复到正常状态和小尺寸,如下所示:
我不知道 CardView 或 RelativeLayout 发生了什么使我的应用程序数据和缓存使用高空间....也许有人可以解释一下。提前致谢。
最佳答案
约束布局有
从左到右的错误修复(布局参数被缓存,防止您在运行时更改它们)
第一个布局的性能改进
当两个维度都设置为 MATCH_CONSTRAINT (0dp) 时,比率支持得到扩展以工作。这处理了一个维度受到约束而您想要将另一个维度定义为比率的情况。
所以肯定你在约束布局中有这些性能提升,所以最好使用它而不是相对布局。
尝试了解更多here
关于android - ConstraintLayout 与 RelativeLayout 和 CardView - 缓存和内存空间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43345630/
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
ruby如何管理内存。例如:如果我们在执行过程中采用C程序,则以下是内存模型。类似于这个ruby如何处理内存。C:__________________|||stack|||------------------||||------------------|||||Heap|||||__________________|||data|__________________|text|__________________Ruby:? 最佳答案 Ruby中没有“内存”这样的东西。Class#allocate分配一个对象并返回该对象。这就是程序
我试过重新启动apache,缓存的页面仍然出现,所以一定有一个文件夹在某个地方。我没有“公共(public)/缓存”,那么我还应该查看哪些其他地方?是否有一个URL标志也可以触发此效果? 最佳答案 您需要触摸一个文件才能清除phusion,例如:touch/webapps/mycook/tmp/restart.txt参见docs 关于ruby-如何在Ubuntu中清除RubyPhusionPassenger的缓存?,我们在StackOverflow上找到一个类似的问题:
尝试在我的RoR应用程序中实现计数器缓存列时出现错误Unknownkey(s):counter_cache。我在这个问题中实现了模型关联:Modelassociationquestion这是我的迁移:classAddVideoVotesCountToVideos0Video.reset_column_informationVideo.find(:all).eachdo|p|p.update_attributes:videos_votes_count,p.video_votes.lengthendenddefself.downremove_column:videos,:video_vot
我们目前正在为ROR3.2开发自定义cms引擎。在这个过程中,我们希望成为我们的rails应用程序中的一等公民的几个类类型起源,这意味着它们应该驻留在应用程序的app文件夹下,它是插件。目前我们有以下类型:数据源数据类型查看我在app文件夹下创建了多个目录来保存这些:应用/数据源应用/数据类型应用/View更多类型将随之而来,我有点担心应用程序文件夹被这么多目录污染。因此,我想将它们移动到一个子目录/模块中,该子目录/模块包含cms定义的所有类型。所有类都应位于MyCms命名空间内,目录布局应如下所示:应用程序/my_cms/data_source应用程序/my_cms/data_ty
最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路
你好,我无法成功如何在散列中删除key后释放内存。当我从哈希中删除键时,内存不会释放,也不会在手动调用GC.start后释放。当从Hash中删除键并且这些对象在某处泄漏时,这是预期的行为还是GC不释放内存?如何在Ruby中删除Hash中的键并在内存中取消分配它?例子:irb(main):001:0>`ps-orss=-p#{Process.pid}`.to_i=>4748irb(main):002:0>a={}=>{}irb(main):003:0>1000000.times{|i|a[i]="test#{i}"}=>1000000irb(main):004:0>`ps-orss=-p
这会导致Ruby出现内存问题吗?我知道如果大小超过10KB,Open-URI会写入TempFile。但是HTTParty会在写入TempFile之前尝试将整个PDF保存到内存吗?src=Tempfile.new("file.pdf")src.binmodesrc.writeHTTParty.get("large_file.pdf").parsed_response 最佳答案 您可以使用Net::HTTP。参见thedocumentation(特别是标题为“流媒体响应机构”的部分)。这是文档中的示例:uri=URI('http://e
当我尝试进行bundle安装时,我的gem_path和gem_home指向/usr/local/rvm/gems/我没有写入权限,并且由于权限无效而失败。因此,我已将两个路径都更改为我具有写入权限的本地目录。这样做时,我进行了bundle安装,我得到:bruno@test6:~$bundleinstallFetchinggemmetadatafromhttps://rubygems.org/.........Fetchinggemmetadatafromhttps://rubygems.org/..Bundler::GemspecError:Couldnotreadgemat/afs/
在部署在heroku上的Rails应用程序(v:3.1)中,我在内存中获得了更多具有相同ID的对象。我的heroku控制台日志:>>Project.find_all_by_id(92).size=>2>>ActiveRecord::Base.connection.execute('select*fromprojectswhereid=92').to_a.size=>1这怎么可能?可能是什么问题? 最佳答案 解决方案根据您的SQL查询,您的数据库中显然没有重复条目。也许您的类项目中的size或length方法已被覆盖。我试过find_