2012-11-26 5 views
0

날 도와안드로이드 레이아웃 작업 문제

내 XML 레이아웃이이 main.xml 내가 필요 정확히 수행 팽창이

<LinearLayout width=fill height=wrap orient=horizontal> 
    <LinearLayout width=0 height=wrap weight=1>...</> 
    <LinearLayout width=0 height=wrap weight=1>...</> 
    <LinearLayout width=0 height=wrap weight=1>...</> 
    <LinearLayout width=wrap height=wrap weight=0>...</> 
</LinearLayout> 

같은 것입니다하시기 바랍니다.

그러나 [예를 들어] 두 번째 하위 레이아웃 가시성이 GONE 인 활동을 시작하고 런타임에 VISIBLE으로 만들면 전체 루트/상위 레이아웃이 매우 나 빠진다. [sublayouts에서] 서브 뷰가 서로 어지럽게 보였지만, 위치가 재 계산되지 않아서 새로운 linearlayout이 표시되는 것처럼 보입니다.

requestLayout()forceLayout()이 도움이되지 않았습니다.

어떻게하면 루트 레이아웃을 액티비티가 방금 시작되었을 때와 동일한 작업으로 할 수 있습니까?

+0

코드 또는 레이아웃에 문제가있는 경우 "의사 코드"는 좋지 않습니다. 여기에 사용중인 정확한 레이아웃을 게시하십시오. –

답변

0
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" 
    android:weightSum="4"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1">........</LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1">........</LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1">........</LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_weight="1">........</LinearLayout> 

</LinearLayout> 
+0

android 설정 : weightSum은 정말 재미 있습니다. 사용하겠습니다. 감사합니다)) – mjollneer

+0

환영합니다 :) –

0

결국 나는 작동합니다. 이제는 모든 것이 올바르게 업데이트됩니다. 그러나 이것이 실제 해결책이 아닐 수도 있습니다. 방금 레이아웃 표시를 onWindowFocusChanged 콜백으로 다시 계산하고 android:weightSum 코드를 수동으로 설정하는 코드를 옮겼습니다. 믿음 onSizeChanged 콜백도 도움이 될 수 있습니다.