Android的 - 得到父布局的高度 [英] Android - get Height of the parent layout

查看:102
本文介绍了Android的 - 得到父布局的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要确定父布局,而我必须添加我的观点的可用高度和宽度。

I want to determine the available height and width of the parent layout to which I have to add my view.

我已经使用的布局很多方法,如

I have used many methods on layout like

  • layout.getHeight()
  • layout.getRootView()的getHeight()

所有这些方法返回0(零)作为结果。

All these methods return 0(zero) as the result.

我的主要要求是能够得到宽的视图是布局的宽度的一些%。

My main requirement is to be able to give width to a view that is some % of the width of the layout .

此外,我不想使用标签这一点。我想通过code做到这一点。

Also I dont want to use tag for this. I want to do it through code.

在此先感谢。

推荐答案

确定。我发现了一个解决的办法。我们可以在活动屏幕hieght的方法是

Ok. I found a solution to it. The way we can get hieght of the screen in activity is

getApplicationContext()。getResources()。getDisplayMetrics()。heightPixels

getApplicationContext().getResources().getDisplayMetrics().heightPixels

但我仍然不知道如何让家长布置的像素dimentions?

But I still dont know how to get the pixel dimentions of parent layout?

这篇关于Android的 - 得到父布局的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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