1

对于我的应用程序,我使用的是手风琴布局,其中我有三个面板,并且我正在尝试将面板(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);
                }

            }
        });

    }
4

1 回答 1

1

如果您在AndroidManifest文件中包含需要系统来处理方向更改:

android:configChanges="orientation"

你应该在里面实现你的代码onConfigurationChanged(),否则它应该在里面onResume()(因为活动被暂停然后恢复并且不再调用 onCreate 。

于 2012-12-17T09:11:21.500 回答