对于我的应用程序,我使用的是我有三个面板的手风琴布局,并且我尝试将面板(texview)大小设置为适合该设备的大小当屏幕方向发生变化时,此功能不起作用。根据设备处于横向时的高度,我的视图尺寸不会改变。请帮助我。getHeight()的视图给出了相同的结果在纵向和横向在Android中
这是我的代码
if(layoutView.getId() == R.id.Advertitletext)
{
openLayout = panel1;
v = panel1.getVisibility();
hideThemAll();
if(v != View.VISIBLE)
{
panel1.setVisibility(View.VISIBLE);
params = advertoutput.getLayoutParams();
params.height = parentLinear.getHeight()-msgrecvtitle.getHeight()-msgsenttitle.getHeight()-mLogCheck.getHeight()-PearActivity.peartabs.getHeight();
advertoutput.setLayoutParams(params);
}
}
这是我onConfiguration()方法
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
ViewTreeObserver observer = parentLinear.getViewTreeObserver();
observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
parentLinear.getViewTreeObserver().removeGlobalOnLayoutListener(this);
if(openLayout==panel1){
params = advertoutput.getLayoutParams();
params.height = parentLinear.getHeight()-msgrecvtitle.getHeight()-msgsenttitle.getHeight()-mLogCheck.getHeight()-PearActivity.peartabs.getHeight();
advertoutput.setLayoutParams(params);
}
else if(openLayout == panel2){
params = msgrecvoutput.getLayoutParams();
params.height = parentLinear.getHeight()-adverttitle.getHeight()-msgsenttitle.getHeight()-mLogCheck.getHeight()-PearActivity.peartabs.getHeight();
msgrecvoutput.setLayoutParams(params);
}else if(openLayout == panel3){
params = msgsentoutput.getLayoutParams();
params.height = parentLinear.getHeight()-adverttitle.getHeight()-msgrecvtitle.getHeight()-mLogCheck.getHeight()-PearActivity.peartabs.getHeight();
msgsentoutput.setLayoutParams(params);
}
}
});
}
这段代码是否在onCreate中? –
雅这里面onCreate()像这样三个视图有其他loop.Inside configurationChanged()方法它给以前的方向的高度,而不是最新的一个 – AndroidCrazy