2016-04-21 58 views
0

我試圖讓我的應用的用戶切換UI爲標準方向或「左撇子」。我不確定我需要編程的解決方案的程度如何,考慮到Android可能會提供一種抽象的方式來輕鬆完成此任務。Android:以編程方式將XML佈局更改爲「左撇子翻轉」

從外觀上看,標準方向將是:standard layout

和左撇子翻轉方向將是:enter image description here

所以,目前我所想嘗試的是XML佈局,組件的手動重排按組件,在菜單按鈕的onTouch()邏輯中。

我覺得可能有比這更簡單的方法。有什麼建議麼?是一系列編程式調用來重新排列視圖的最佳方式嗎?下面的Xml文件。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" 
    android:baselineAligned="false" 
    android:keepScreenOn="true"> 

    <LinearLayout  
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1.40" 
     android:orientation="vertical" 
     android:id="@+id/toolbarGestureOverlay" > 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:orientation="vertical" 
     android:layout_weight="3.60" 
     android:id="@+id/openglsurface"> 
    </LinearLayout>  
</LinearLayout> 
+0

回你想多遠支持?在4.2+上,您可以設置頂層佈局的layoutDirection。 –

回答

1

我想你可以通過使用rotate函數(API從11只)存檔:

View view = findViewById(R.id.yourParentLayout); 
view.setRotation(270); 
// you must canculate your screen size to make your view fit your screen. 
view.getLayoutParams().width = 800; 
view.getLayoutParams().height = 480; 
// For flip, you can rotate a long x or y axis: 
view.setRotationY(180); 
+0

對不起,這不起作用,因爲左撇子視圖不是標準視圖的簡單旋轉。左手翻轉的藍色視圖不是簡單的旋轉,而是垂直鏡像。 – Cody

+0

@Cody你有沒有試過它?你不知道它旋轉180度嗎? –

+0

我的照片不夠詳細。左手翻轉圖像中的藍色佈局實際上並未旋轉,只是沿垂直軸翻轉。如果我將藍色佈局旋轉180度,它會顛倒(因爲無論方向如何,字符'X'看起來都是相同的,您只是無法分辨圖片) – Cody

相關問題