好时间来手动布局一个活动的看法

好时间来手动布局一个活动的看法

本文介绍了好时间来手动布局一个活动的看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个活动凡在我需要做在运行时的一些布局(在这种特定情况下,我需要设置的指标范围( ExpandableListView.setIndicatorBound ),从而使组指标对齐到视图而不是默认的左右侧。

I have this activity where in I need to do some layout at runtime (in this particular instance I need to set the indicator bounds (ExpandableListView.setIndicatorBound) so that the group indicator aligns to the right side of the view instead of the default left.

我这有code在我的活动:的onCreate

I've got this code in my Activity:onCreate:

int viewWidth = mListView.getWidth();
int groupIndicatorWidth = getResources().getDrawable(R.drawable.up).getMinimumWidth();
mListView.setIndicatorBounds(viewWidth - groupIndicatorWidth, viewWidth);
app.fetchItems(this);

完全可以理解, viewWidth 原来是 0 在运行时。

我的问题是什么方法,我应该实行/过载时,该视图的孩子就已经奠定了和他们的尺寸是否有效?基本上,在Windows上,我们一般会放在筛上部分/ onResize受到这样的code。

My question is what method should I implement/overload when the view's children would have been laid out and their dimensions valid? Basically on Windows we would generally put such code in OnSize/OnResize.

我发现活动:onPostCreate 活动:onPostResume ,但我也发现了这个在文档 - 应用程序一般不会实现此方法;它是为系统类做申请code运行后最终初始化

I found Activity:onPostCreate and Activity:onPostResume, but I also found this in the docs - "Applications will generally not implement this method; it is intended for system classes to do final initialization after application code has run."

修改

发现这个线程有哪几种解决方法所示:
Android:需要在课堂上使用onSizeChanged为View.getWidth /身高()扩展活动

Found this thread which has several workarounds listed:Android: Need to use onSizeChanged for View.getWidth/Height() in class extending Activity

推荐答案

最明显的办法知道,当视图的大小被改变(在你的榜样的ListView),是延长这一观点并覆盖其 onSizeChanged(INT W,INT小时,INT oldw,诠释oldh) 方法。

The most obvious way to know, when the size of the view is changed (ListView in your example), is to extend that view and override its onSizeChanged(int w, int h, int oldw, int oldh) method.

这篇关于好时间来手动布局一个活动的看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:38