2013-06-20 5 views
0

높이가 0인데 로그 cat에 인쇄 중입니다. 이 포함Hight 모드가 0이거나 ViewSwitcher는 android의 realViewSwitcher에서만 EXACTLY 모드에서만 사용할 수 있습니다.

RealViewSwitcher realViewSwitcher = (RealViewSwitcher) findViewById(R.id.horizontal_pager); 
     realViewSwitcher.setOnScreenSwitchListener(onScreenSwitchListener); 

RealViewSwitcher.java 파일 : @Override

protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) { 
super.onMeasure(widthMeasureSpec, heightMeasureSpec); 

final int width = MeasureSpec.getSize(widthMeasureSpec); 
final int widthMode = MeasureSpec.getMode(widthMeasureSpec); 
if (widthMode != MeasureSpec.EXACTLY) { 
    Log.d("TAG", "First MeastueSpece.Exactly Out Put:"+MeasureSpec.EXACTLY); 
    Log.d("TAG", "First Width Out Put:"+widthMode); 
    throw new IllegalStateException("ViewSwitcher can only be used in EXACTLY mode. at Width Mode"); 
} 

final int heightMode = MeasureSpec.getMode(heightMeasureSpec); 
if (heightMode != MeasureSpec.EXACTLY) { 

    Log.d("TAG", "First MeastueSpece.Exactly Out Put:"+MeasureSpec.EXACTLY); 
    Log.d("TAG", "First heightModeOut Put:"+heightMode); 
    throw new IllegalStateException("ViewSwitcher can only be used in EXACTLY mode. at Height Mode"); 
} 
...... 

를 레이아웃 파일에서 : 나는 로그 캣이있어

<ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginBottom="45dp" 
     android:layout_marginTop="54dp" > 

     <com.test.RealViewSwitcher 
      android:id="@+id/horizontal_pager" 
      android:layout_width="fill_parent" 
      android:layout_height="0px" 
      android:orientation="vertical" 
      android:layout_weight="1" > 
     </com.test.RealViewSwitcher> 
    </ScrollView> 

MainJava 파일에

:

06-20 09:42:55.952: D/TAG(1329): First heightMode Out Put:0 
06-20 09:42:55.962: D/TAG(1329): First MeastueSpece.Exactly Out Put:1073741824 
06-20 09:42:55.962: W/Trace(1329): Unexpected value from nativeGetEnabledTags: 0 
06-20 09:42:55.972: W/Trace(1329): Unexpected value from nativeGetEnabledTags: 0 
06-20 09:42:55.972: D/AndroidRuntime(1329): Shutting down VM 
06-20 09:42:55.984: W/dalvikvm(1329): threadid=1: thread exiting with uncaught exception (group=0x40a70930) 
06-20 09:42:56.253: E/AndroidRuntime(1329): FATAL EXCEPTION: main 
06-20 09:42:56.253: E/AndroidRuntime(1329): java.lang.IllegalStateException: ViewSwitcher can only be used in EXACTLY mode. at Height Mode 

답변

0

그냥 높이를 하드 코딩하십시오. 다음으로 교체하십시오 :

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_marginBottom="45dp" 
    android:layout_marginTop="54dp" > 

    <com.test.RealViewSwitcher 
     android:id="@+id/horizontal_pager" 
     android:layout_width="fill_parent" 
     android:layout_height="550dp" 
     android:orientation="vertical" 
     android:layout_weight="1" > 
    </com.test.RealViewSwitcher> 
</ScrollView>