2012-05-03 45 views
0

我發現了一個Android的bug,給了我很多頭痛。SlidingDrawer旋轉使用onConfigurationChanged

活動的清單:

<activity 
     android:name=".ActivityTest" 
     android:configChanges="orientation" 
     android:label="@string/app_name" /> 

佈局:

<TextView 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="TEST" /> 

<SlidingDrawer 
    android:id="@+id/drawer" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:content="@+id/content" 
    android:handle="@+id/handle" 
    android:orientation="vertical" > 

    <ImageView 
     android:id="@id/handle" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:src="@drawable/ic_launcher" /> 

    <LinearLayout 
     android:id="@id/content" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

     <Button 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:text="Big Big Button" /> 
    </LinearLayout> 
</SlidingDrawer> 

現在..抓住抽屜的把手,並將其移動到中間和維護手指在旋轉裝置時...

抽屜尺寸得到所有螺絲...,直到它完全打開。

Drawer in portrait closed Drawer half opened in portrait Drawer after rotation to landscape not resized (with finger still pressing)

有人對如何解決它的任何IDEIA?我試圖看看SlidingDrawer的開放代碼,以檢查它打開時爲什麼會變好。但沒有運氣。

不處理我自己的旋轉沒有我從來沒有與滑動抽屜的工作,我很願意選擇加入現在一個選項...

回答

0

好了,總算把一些技巧修復它...觸摸事件,有時沒有得到各方面的意見與半開的抽屜旋轉後...

首先,我延長了抽屜,然後:添加一些代碼給一些方法:

@Override 
protected void onLayout(boolean changed, int l, int t, int r, int b) 
{ 
    if (mTracking && !rotationStopTracking) 
    { 
     return; 
    } 
    else if (rotationStopTracking) 
    { 
     rotationStopTracking = false; 
     if (isMoving()) 
     { 
      animateOpen(); 
      close(); 
     }else{ 
      animateOpen(); 
     } 
    } 

    ... 

    } 


//Called from Activity onConfigurationChanged 
public void enableRotationResize() 
{ 
    if (mTracking) 
    { 
     mTracking = false; 
     rotationStopTracking = true; 
    } 
} 
0

,所以我只是要拋出想法在這裏,也許它堅持到牆上。

如果每當onConfiguration被調用時,會得到scren的寬度,並將滑動drawer的layout_width設置爲該值?它看起來就像當你停下來並旋轉屏幕時,即寬度(旋轉後),與旋轉前的寬度相同。也許如果你明確地設置寬度,它會正確地展開。

+0

在那裏,做到了。 – neteinstein