【发布时间】:2012-10-18 18:08:31
【问题描述】:
我有一个如下所示的布局。它被代码膨胀并添加到 HorizontalScrollView 中,有时数百次,并导致内存问题。
我想知道是否可以做些什么来提高效率?最初我使用 LinearLayouts,用 RelativeLayout 代替它对滚动产生了巨大的影响。现在我想知道它是否可以进一步改进?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="156dp"
android:layout_height="254dp"
android:paddingLeft="7dip"
android:paddingRight="7dip">
<FrameLayout android:id="@+id/button_frame"
android:layout_width="156dp"
android:layout_height="218dp">
<ImageView android:id="@+id/button_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/image_bg"
/>
<ImageView android:id="@+id/button_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom|right"
/>
<TextView android:id="@+id/button_select"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:background="@drawable/btn_selector_bg_selected"
/>
<TextView android:id="@+id/button_selected"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:background="@drawable/title_bg_selected"/>
</FrameLayout>
<TextView
android:id="@+id/button_title"
android:layout_width="156dp"
android:layout_height="36dp"
android:textColor="#ffffff"
android:singleLine="true"
android:textSize="13sp"
android:textStyle="bold"
android:gravity="center_vertical|left"
android:ellipsize="end"
android:paddingLeft="30dip"
android:paddingRight="5dip"
android:layout_below="@id/button_frame"
android:background="@drawable/title_bg"/>
</RelativeLayout>
ImageView button_image 是使用 AQuery 图像缓存填充的,所以我不确定我是否可以做更多的事情来改进图像的处理方式。但非常感谢任何有关改进的提示。
【问题讨论】:
-
你试过使用merge吗?
-
有趣,我不知道合并!除了以下建议的布局更改之外,我肯定会尝试一下。
标签: android performance android-layout