Android的XML:百分比高度和宽度,创造出独特的布局 [英] Android XML: Percentage Height and width to create unique layout

查看:234
本文介绍了Android的XML:百分比高度和宽度,创造出独特的布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说过这么多的重量等,但是大部分的教程参见总是宽度的百分比。我希望与布局做如下设置:

I've heard so much about weight etc. However most of the tutorials refer always to width percentage. I wish to do the following setups with layouts:

任何人都知道如何做到这一点?我卡住了!

Anyone know how to do this? I'm stuck!

推荐答案

由于现在存在它%的支持库是没有必要的使用的LinearLayout 配重块了。

好吧好吧,你是第一个布局应该是pretty容易,请查看以下code:

Well ok, you're first layout should be pretty easy, check the following code:

<?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="vertical" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal"
        android:weightSum="3" >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:weightSum="5" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="3"
                android:background="@android:color/darker_gray" >
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="2"
                android:background="@android:color/white" >
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:weightSum="9" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="3"
                android:background="@android:color/holo_red_light" >
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="6"
                android:background="@android:color/holo_orange_light" >
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="fill_parent"
            android:layout_weight="1"
            android:orientation="vertical"
            android:weightSum="9" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="6"
                android:background="@android:color/holo_blue_dark" >
            </LinearLayout>

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="3"
                android:background="@android:color/holo_green_dark" >
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

输出:

第二个似乎不可能的权重有关。 Furthere更多的我会建议你不要配重块用太多的嵌套的线性布局,因为这是根据以下的链接

The second one seems not possible to do with weights. Furthere more I would recommend that you don't use too much nested Linear Layouts with weights since this is a huge performance issue according to the following Link

这篇关于Android的XML:百分比高度和宽度,创造出独特的布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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