2012-12-17 15 views
1

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

      } 
     }); 

    } 
+0

这段代码是否在onCreate中? –

+0

雅这里面onCreate()像这样三个视图有其他loop.Inside configurationChanged()方法它给以前的方向的高度,而不是最新的一个 – AndroidCrazy

回答

1

如果您在您的AndroidManifest文件,你需要系统处理方向的变化:

android:configChanges="orientation" 

您应该在之内执行您的代码0,否则它应该在onResume()之内(因为活动已暂停然后恢复,并且不会再次调用onCreate。

+0

雅我写了onConfigurationChanged()同样的代码,但我也我正在获得旧的价值。 – AndroidCrazy

+0

您确定在Manifest文件中添加了android:configChanges =“orientation”吗? –

+0

ya我在清单中加入了 – AndroidCrazy

相关问题