1
我想基於FrameLayout裏可能被旋轉90度順時針/逆時針創建ViewGroup中,它仍然會被正確旋轉(90度)的ViewGroup根
工作到目前爲止,我的成績不是很sucesful。到目前爲止,它看起來像(旋轉前左側,右後;爲鮮紅色抱歉)
佈局的活動
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.example.TestProject.RotatedFrameLayout
android:id="@+id/container"
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00F"/>
</RelativeLayout>
RotatedFrameLayout
public class RotatedFrameLayout extends FrameLayout {
private boolean firstMeasure = true;
public RotatedFrameLayout(Context context) {
super(context);
init();
}
public RotatedFrameLayout(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public RotatedFrameLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
private void init() {
setRotation(90f);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(heightMeasureSpec, widthMeasureSpec);
}
}
部分額外信息
- 我不想用動畫旋轉,因爲按鈕是不可點擊這樣
- 我不想使用風景模式,因爲在屏幕上的導航按鈕景觀花了很多空間的Nexus 7 (這就是爲什麼我想馬麗娟是旋轉
- 的主要原因似乎屏幕只有左,右側出界
您好,感謝提示。我交換了尺寸並旋轉了它,嘗試了各種組合,到目前爲止沒有成功,但是在上面的代碼不會中斷按鈕觸摸行爲(它仍然是可點擊的)。更多的問題與適當的大小。這值得麼?在屏幕導航按鈕上執行某些操作是很有想法的,這些按鈕在較小的設備上佔用了大量空間:/ 10英寸平板電腦上,這不是一個問題。 – outlying 2013-02-22 14:14:18
自API11以來,我還沒有看到setRotation方法。我會看看它是如何工作的。我們支持舊的Android版本,所以我們確實使用它。 – Leonidos 2013-02-22 14:26:35
更新我的答案。我做了幾乎和你一樣,它的工作原理... – Leonidos 2013-02-22 15:16:39