如何使RelativeLayout的不占用整个屏幕? [英] How to make RelativeLayout not take up the whole screen?

查看:232
本文介绍了如何使RelativeLayout的不占用整个屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我有一个相对布局定义编程

Currently, I have a relative layout defined programatically

 RelativeLayout layout = new RelativeLayout(this);

然后我加textviews和按钮像这样

then I add textviews and buttons like this

 layout.addView(myText, params);
 layout.addView(myBtn, param);

然而,这使得整个画面充满了我的RelativeLayout,我怎么(编程)仅设置一定数量的像素(DP)占用屏幕?我的目标是能有像屏幕RelativeLayout的下半部

However, this makes the entire screen fill up with my relativelayout, how do I (programatically) set only certain number of pixels(dp) take up the screen? My goal is to have like the bottom half of the screen relativelayout

Anyhelp?

编辑:这就是我想实现最终:的http:/ /i.imgur.com/n1ckBN7.png

This is what I am trying to achieve ultimately : http://i.imgur.com/n1ckBN7.png

我觉得这(在XML中)可能会帮助我

I think this (in XML) might help me

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="200dp">

我试图将其转换成这样的Java之前,我添加textviews:

I tried converting it into java like this before I add the textviews:

 parameters_layout = new 
         RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 
     200);
 layout.setLayoutParams(parameters_layout);

编辑2
我尝试添加:

EDIT 2 I tried adding:

    parameters_layout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    parameters_layout.addRule(RelativeLayout.ALIGN_BOTTOM, RelativeLayout.TRUE);
    layout.setGravity(Gravity.BOTTOM);
    layout.setLayoutParams(parameters_layout);

仍然没有运气

推荐答案

据我的图片中看到,你可以把一切都在覆盖一切的RelativeLayout,而底部的观点是一致的底部(使用ALIGN家长底部这一点)。

according to what i see in the image, you can either put everything in a relativeLayout that covers everything, while the bottom views are aligned to the bottom (use align parent bottom for this).

另外,您也可以设置仅底部(可以是任何你希望的布局)拥有的底部重力窗口本身内。

alternatively, you can set only the bottom part (which can be any layout you wish) to have a gravity of "bottom" inside the window itself.

事实上,我最近被问及创建具有透明背景的对话就在不久前,所以它可能对你有所帮助。 <一href=\"http://stackoverflow.com/questions/18337533/create-a-transparent-dialog-on-top-of-activity\">here's链接。从我的理解,一个非常类似的方法可以对活动进行。

in fact, i've recently asked about creating a dialog with transparent background not so long ago, so it might be helpful for you. here's the link . from my understanding, a very similar approach can be done for activities.

这篇关于如何使RelativeLayout的不占用整个屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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