Android的布局复杂的线性和相对 [英] Android complex layout linear and relative

查看:122
本文介绍了Android的布局复杂的线性和相对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要实现像图中所示的布局,不知道以实现所需的设计的最佳组合。
我设计的7平板电脑,并希望在设计上伸展10井

I have to implement a layout like shown in the diagram, and I do not know the best combination to achieve the required design. I'm designing for the 7" tablet and want the design to stretch well on the 10"

我想喜欢的布局1,2,3,4,5是LinearLayouts,正确的?

I assume layouts like 1, 2, 3, 4, 5 are LinearLayouts, correct?

*什么是活动布局?我试过RelativeLayout的,但我不能分发布局1安培之间的宽度; 2及3(采用了android:layout_weight)

*What is the activity layout? I tried the RelativeLayout but I could NOT distribute the width between layouts 1 & 2 & 3 (using android:layout_weight)

*我试过表示平的LinearLayout整个活动,但我不能正确地添加页眉和页脚布局主表示平线性布局

*I tried the Horzontal LinearLayout for the whole activity, but I could not add the header and footer layouts correctly to the main horzontal linear layout

我阅读文档和教程,但找不到线索,这种复杂的设计,请大家帮帮忙。

I read the documentation and tutorials but could not find a clue to this complex design, please help.

还有什么是嵌套布局的性能影响?

Also what is the performance hit of the nested layouts?

谢谢,

推荐答案

您可以尝试这样的事情,而且,正如别人所说,在这个级别你不会有性能问题

You could try something like this, and, as someone else said,at this level you will not have performance issues

<?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"
android:weightSum="1" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.2"
    android:background="@android:color/holo_orange_light"
    android:orientation="horizontal"
    android:weightSum="1" >

    <View
        android:id="@+id/view1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_weight="0.2"
        android:background="@android:color/black" />

    <View
        android:id="@+id/view2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_weight="0.8"
        android:background="@android:color/black" />
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.6"
    android:background="@android:color/holo_blue_light"
    android:orientation="horizontal"
    android:weightSum="1" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:layout_weight="0.2"
        android:background="@android:color/holo_purple"
        android:orientation="vertical"
        android:weightSum="1" >

        <View
            android:id="@+id/view1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_margin="10dp"
            android:layout_weight="0.2"
            android:background="@android:color/black" />

        <View
            android:id="@+id/view1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_margin="10dp"
            android:layout_weight="0.3"
            android:background="@android:color/black" />

        <View
            android:id="@+id/view2"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_margin="10dp"
            android:layout_weight="0.5"
            android:background="@android:color/black" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:layout_weight="0.4"
        android:background="@android:color/holo_red_dark"
        android:orientation="vertical"
        android:weightSum="1" >

        <View
            android:id="@+id/view1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_margin="10dp"
            android:layout_weight="0.33"
            android:background="@android:color/black" />

        <View
            android:id="@+id/view1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_margin="10dp"
            android:layout_weight="0.33"
            android:background="@android:color/black" />

        <View
            android:id="@+id/view2"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_margin="10dp"
            android:layout_weight="0.33"
            android:background="@android:color/black" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:layout_weight="0.4"
        android:background="@android:color/darker_gray"
        android:orientation="vertical"
        android:weightSum="1" >

        <View
            android:id="@+id/view1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_margin="10dp"
            android:layout_weight="0.5"
            android:background="@android:color/black" />

        <View
            android:id="@+id/view2"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_margin="10dp"
            android:layout_weight="0.5"
            android:background="@android:color/black" />
    </LinearLayout>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.2"
    android:background="@android:color/holo_green_light"
    android:orientation="horizontal"
    android:weightSum="1" >

    <View
        android:id="@+id/view1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_weight="0.2"
        android:background="@android:color/black" />

    <View
        android:id="@+id/view1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_weight="0.3"
        android:background="@android:color/black" />

    <View
        android:id="@+id/view2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:layout_weight="0.5"
        android:background="@android:color/black" />
</LinearLayout>

</LinearLayout>

这篇关于Android的布局复杂的线性和相对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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