对于我的应用程序,我使用的是手风琴布局,其中我有三个面板,我正在尝试将面板(texview)大小设置为适合设备高度的大小。当这种情况发生变化时,这不起作用屏幕方向。我的视图大小不会根据设备在横向时的高度而改变。请帮我这个。
这是我的代码
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);
}
}
});
}
答案 0 :(得分:1)
如果您在AndroidManifest
文件中包含您需要系统来处理方向更改:
android:configChanges="orientation"
您应该在onConfigurationChanged()
中实现您的代码,否则它应该在onResume()
内(因为活动暂停然后恢复,并且不会再次调用onCreate。