English 中文(简体)
衬内重量对性能不利
原标题:Nested weights are bad for performance

在这里的布局中, 我为底部的 2 个按钮获得此信息, 尽管我只为布局中另一个部件设定了权重, 而不是按钮的母部件( 消息文本部件) 。 我在做什么错事? 谢谢 。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<LinearLayout
    android:orientation="horizontal"
    android:layout_marginTop="10dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView  
        android:layout_marginLeft="10dip"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/status_label"
        android:textStyle="bold"
        android:textSize="20dip"
        android:textColor="#FEFF80"/>
    <TextView  
        android:id="@+id/statusText"
        android:layout_marginLeft="10dip"
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="@string/unsent"
        android:textSize="20dip"
        android:textColor="#FEFF80"/>
</LinearLayout>
<TextView
    android:layout_width="fill_parent"
    android:layout_marginTop="10dip"
    android:layout_height="1dip"
    android:background="#FEFF80"/>
<TextView  
    android:layout_marginTop="10dip"
    android:layout_marginLeft="11dip"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/message_number_caption"
    android:textSize="15dip"/>
<EditText
    android:id="@+id/messageNumber"
    android:inputType="phone"
    android:layout_marginTop="10dip"
    android:layout_marginLeft="10dip"
    android:layout_marginRight="10dip"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"/>
<TextView  
    android:layout_marginTop="30dip"
    android:layout_marginLeft="11dip"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/message_text_caption"
    android:textSize="15dip"/>
<EditText android:inputType="text"
    android:id="@+id/messageText"
    android:layout_marginTop="10dip"
    android:layout_marginLeft="10dip"
    android:layout_marginRight="10dip"
    android:layout_weight="1.0"
    android:layout_width="fill_parent" 
    android:layout_height="0dip"/>
<LinearLayout
    android:orientation="horizontal"
    android:layout_marginTop="10dip"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <Button
        android:id="@+id/sendButton"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"
        android:layout_width="0dip"
        android:layout_height="wrap_content"
        android:layout_weight="0.5" 
        android:text="@string/send_button_label"
        android:textSize="15dip"/>
    <Button
        android:id="@+id/resetButton"
        android:layout_marginLeft="10dip"
        android:layout_marginRight="10dip"
        android:layout_width="0dip" 
        android:layout_height="wrap_content" 
        android:layout_weight="0.5"
        android:text="@string/reset_button_label"
        android:textSize="15dip"/>
</LinearLayout>
</LinearLayout>
最佳回答

您已经指定了重量为 1 的编辑文本( id/ messesageText) - 您是否打算这样做, 因为线性布局中的其他部件没有重量?

然后在下面,你有一个线性外延, 有两个按钮使用重量合法。

N.B. 它是一个相当简单的布局,所以你可能没事。如果你有更深层次的层次, 有更多的布局和部件, 那么你更有可能看到一个缓慢的下降。

问题回答

您没有做错什么, 它只是一个警告。 Android 查看引擎解释您的 XML 并构建查看对象。 Google 已经决定, 在布局中嵌套重( 即有 < code> 和 mid:layout_ weight 属性的视图), 在另一个布局中导致视图引擎运行不良, 他们建议您不这样做 。

如果有另一种方法可以实现您在不使用 andorid:layout_ weight 属性的情况下构建的布局, 最好这样做。 否则的话, 您的视图可能会稍慢加载 。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签