替代嵌套的权重与LinearLayouts [英] Alternative to nested weights with LinearLayouts

查看:216
本文介绍了替代嵌套的权重与LinearLayouts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现以下目标:

这适用于以下布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal">

    <LinearLayout
        android:layout_weight="3"
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <fragment 
            android:name="com.bobjohn.DetailsMenuFragment"
            android:id="@+id/detailsMenuFragment"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="6"
            />

        <fragment 
            android:name="com.bobjohn.SummaryFragment"
            android:id="@+id/summaryFragment"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_margin="10dp"
            android:layout_weight="4"/>
    </LinearLayout>

    <TextView 
        android:layout_width="0dp"
        android:layout_weight="7"
        android:layout_height="fill_parent"
        android:text="Test Text"/>
</LinearLayout>

不过,我得到有关嵌套的权重是不好的业绩预警。我理解的错误,但我不知道该如何前preSS以另一种方式此布局。什么是另类?

However, I get the warning about nested weights being bad for performance. I understand the error but I don't know how to express this layout in another way. What is the alternative?

推荐答案

是的,我们有替代嵌套的的LinearLayout 重量通过Android的%的支持库

Yes we have the alternative for nested LinearLayout weight by android's percent support library

code和概念HERE !

GitHub的项目的位置!

考虑一个简单的布局,我已经完全避免的LinearLayout

Consider this simple layout where I have totally avoided weight property of LinearLayout

%的支持库

<android.support.percent.PercentRelativeLayout
    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="match_parent">
    <TextView
        android:id="@+id/fifty_huntv"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="#ff7acfff"
        android:text="20% - 50%"
        android:textColor="@android:color/white"
        app:layout_heightPercent="20%"
        app:layout_widthPercent="50%" />
    <TextView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_toRightOf="@id/fifty_huntv"
        android:background="#ffff5566"
        android:text="80%-50%"
        app:layout_heightPercent="80%"
        app:layout_widthPercent="50%"
        />

</android.support.percent.PercentRelativeLayout>

真真棒!

这篇关于替代嵌套的权重与LinearLayouts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆