Android的,如何放置两个相对的布局,一个在左边,一个在屏幕的右边? [英] Android, how to place two relative layouts, one on the left, and one on the right of the screen?

查看:1248
本文介绍了Android的,如何放置两个相对的布局,一个在左边,一个在屏幕的右边?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用程序(用于横向屏幕方向),我需要把部件两个相对的布局,一个在屏幕的左边,一个在右边(以填补全尺寸)。

In my Android App (for landscape screen orientation) I need to place widgets to two relative layouts, one on the left of the screen, and one at the right (to fill the full size).

我preFER编程工作(我发现它比XML更灵活)。

I prefer working programmatically (I find it more flexible than xml).

我768,16更好地使用TableLayout作为我来回子布局的父布局?

Shoud I better use a TableLayout as the parent layout fro my sub-layouts?

推荐答案

有关短短两年 RelativeLayouts 彼此相邻,你有多种选择以archieve这一点。一个水平的LinearLayout 将在我看来,最简单。

For just two RelativeLayouts next to each other you have plenty of choice to archieve that. A horizontal LinearLayout would be the easiest in my opinion.

编辑:我永远不会做在code的布局,但因为你可能看了很多与XML文档,你应该能够翻译这个例子。同时用于布局50/50的空间分布。

I never do layouts in code, but since you probably read a lot of docs with XML you should be able to translate this example. Uses a 50/50 space distribution for both layouts.

<LinearLayout android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="horizontal">
    <RelativeLayout android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:layout_weight="1" >

    </RelativeLayout>

    <RelativeLayout android:layout_width="0dp"
                    android:layout_height="fill_parent"
                    android:layout_weight="1" >

    </RelativeLayout>

</LinearLayout>


编辑2:


Edit 2:

肯定的作品,只是尝试这样做:

Definitely works, just tried this:

LinearLayout layoutContainer = new LinearLayout(this);
layoutContainer.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

// Arguments here: width, height, weight
LinearLayout.LayoutParams childLp = new LinearLayout.LayoutParams(0, LayoutParams.FILL_PARENT, 1);

RelativeLayout layoutLeft = new RelativeLayout(this);
layoutContainer.addView(layoutLeft, childLp);

RelativeLayout layoutRight = new RelativeLayout(this);
layoutContainer.addView(layoutRight, childLp);

这篇关于Android的,如何放置两个相对的布局,一个在左边,一个在屏幕的右边?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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