获取RelativeLayout的尺寸 [英] Get RelativeLayout dimensions
本文介绍了获取RelativeLayout的尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何得到一定的布局类似的LinearLayout或RelativeLayout的与layout_width的测量和layout_height设置为wrap_content?使用此方法
How do I get the measurements of a certain layout like linearlayout or relativelayout with its layout_width and layout_height set to wrap_content? using this method
layout.measure(MeasureSpec.makeMeasureSpec(0,
MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0,
MeasureSpec.UNSPECIFIED));
layout.layout(0, 0,
layout.getMeasuredWidth(),
layout.getMeasuredHeight());
返回null。我想出来的RelativeLayout的创建位图图像,有点像一个屏幕截图。
returns null. I'm trying to create a bitmap image out of the relativelayout, kinda like a screenshot.
推荐答案
不要去做就onCreate()方法。试试这个:
Don't do it on the onCreate() method. Try this:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus == true) {
LinearLayout myLinearLayout = (LinearLayout) findViewById(R.id.myLinearLayout);
int layoutWidth = myLinearLayout.getWidth();
int layoutHeight = myLinearLayout.getHeight();
}
}
此方法的onCreate()中,当尺寸是已知的后称为
This method is called after onCreate(), when the sizes are already known.
这篇关于获取RelativeLayout的尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文