相关疑难解决方法(0)

为什么嵌套权重不利于性能?备择方案?

我写了几个布局文件,我使用该layout_weight属性创建不同视图之间的比率.

在某些时候,我开始获得有关嵌套权重的lint警告.

所以,我不知道为什么是坏的嵌套权重的表现,如果有是创建视图的尺寸之间的恒定比率可用于不同的屏幕尺寸,并且并不需要指定大量维DPI值的更有效的方法通过几个布局文件(我的意思是不同的屏幕尺寸).

谢谢!

performance android android-layout

156
推荐指数
4
解决办法
7万
查看次数

Android 布局测量时间随着层次结构的每一步增加而增加一倍

我正在 hierarchyviewer 中分析平板电脑 UI,我注意到测量时间中存在以下模式(从树的底部开始向上移动):

... ~40 毫秒 ... ~80 毫秒 ... ~160 毫秒 ... ~320 毫秒 ... ~640 毫秒 ... ~1280 毫秒 ...

我认为问题是带有嵌套权重的 LinearLayouts,因此我删除了整个层次结构中的所有 LinearLayouts 和权重。现在我有这个:

... ~40 毫秒 ... ~80 毫秒 ... ~160 毫秒 ... ~160 毫秒 ... ~160 毫秒 ... ~310 毫秒 ...

更好,但每隔几个级别它仍然会翻倍。可能是什么原因造成的?

这是此路径的完整层次结构(请原谅长度......请随时向我提出您最好的优化技巧):

[generated layouts]
 *RelativeLayout [309 ms]
   FrameLayout [164 ms]
    NoSaveStateFrameLayout [160 ms]
    *RelativeLayout [151 ms]
     *RelativeLayout [77 ms]
       ListView [45 ms]
        GridLayout [46 ms]
         Spinner [4.4 ms]
          TextView [0.1 ms]
Run Code Online (Sandbox Code Playgroud)

*观看时间加倍 …

android android-layout hierarchyviewer

2
推荐指数
1
解决办法
1162
查看次数

布局重量警告嵌套重量不良表现

我是android的新手.现在我收到了嵌套重量不良表现的警告.我的第一个屏幕上只有一个图像和三个按钮.PLs给了我一些想法.


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/backgroundColor"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    android:weightSum="10"
    >


    <ImageView
        android:layout_weight="4"
        android:id="@+id/imageLogo"
        android:layout_width="wrap_content" 
        android:layout_height="0dip"
        android:contentDescription="@string/Img"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="20dp"
        android:src="@drawable/home_screen_logo" />

    <LinearLayout
       android:layout_weight="6"
       android:layout_width="fill_parent"
    android:layout_height="0dip" 
    android:orientation="vertical" 
    android:gravity="center_horizontal"
        >

        <LinearLayout android:layout_height="0dp" android:layout_width="fill_parent"
            android:layout_weight="1"
            android:id="@+id/temp"></LinearLayout>
    <ImageButton
        android:id="@+id/btnLogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/login"
        android:contentDescription="@string/Img"  
        android:layout_weight="1"
        />
    <LinearLayout android:layout_height="0dp" android:layout_width="fill_parent"
            android:layout_weight="1"></LinearLayout>
    <ImageButton
        android:id="@+id/btnFbLogin"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
         android:background="@drawable/btnfb"
         android:contentDescription="@string/Img"
        />
    <LinearLayout android:layout_height="0dp" android:layout_width="fill_parent"
            android:layout_weight="1"></LinearLayout>
    <ImageButton
        android:id="@+id/btnRegister"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/btnregister"
        android:contentDescription="@string/Img"/>
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)


提前致谢

android android-linearlayout

1
推荐指数
1
解决办法
5440
查看次数