1
私は右にステータスバーを持つレイアウトを作成します回転したレイアウトを右揃えにし、親の高さに合わせるにはどうすればよいですか?
xmlを使用しようとしましたが、これはうまく行かず、バーは右に揃えられず、テキストビューは回転後にrelativelayoutにありません。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="test.com.myapplication.MainActivity">
<RelativeLayout
android:id="@+id/top_bar_land"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:rotation="90"
android:background="@android:color/holo_red_light">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
</RelativeLayout>
そうであっても、私は大規模な数を設定し、私はプログラム的
topBarLand = (RelativeLayout) findViewById(R.id.top_bar_land);
ViewTreeObserver vto = topBarLand.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int w = topBarLand.getWidth();
int h = topBarLand.getHeight();
topBarLand.setRotation(90f);
topBarLand.setTranslationX((w - h)/2);
topBarLand.setTranslationY(Math.abs(h - w)/2);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
topBarLand.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
topBarLand.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});
それを回転しかし、バーの幅は
画面
の高さに合わせることができませんその幅にはまだ変更はありません。RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(1920, h);
topBarLand.setLayoutParams(param);
バーの幅を画面の高さと同じに設定するにはどうすればよいですか?
dependencies {
compile 'rongi.rotate-layout:rotate-layout:2.0.0'
}
をし、あなたのレイアウトをフォーマット:
バディ赤色ビューテイク幅そのときにのみ理由水平になるとfill_parentをとり、90'cを回転させると同じ高さになります(i – Vadivel
デフォルトでは、Androidはビューの中間点をピボットとして使用して回転します。 'transformPivotX'と' transformPivotY'を使って手動での回転を避けることができます。しかし、いくつかの垂直方向のテキストビュー実装を調べることは、回転の代わりに行く方法です。 –