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> 

enter image description here

そうであっても、私は大規模な数を設定し、私はプログラム的

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); 
     } 
    } 
}); 

それを回転しかし、バーの幅は

enter image description here

画面

の高さに合わせることができませんその幅にはまだ変更はありません。

RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(1920, h); 
topBarLand.setLayoutParams(param); 

バーの幅を画面の高さと同じに設定するにはどうすればよいですか?

dependencies { 
    compile 'rongi.rotate-layout:rotate-layout:2.0.0' 
} 

をし、あなたのレイアウトをフォーマット:

+0

バディ赤色ビューテイク幅そのときにのみ理由水平になるとfill_parentをとり、90'cを回転させると同じ高さになります(i – Vadivel

+0

デフォルトでは、Androidはビューの中間点をピボットとして使用して回転します。 'transformPivotX'と' transformPivotY'を使って手動での回転を避けることができます。しかし、いくつかの垂直方向のテキストビュー実装を調べることは、回転の代わりに行く方法です。 –

答えて

0

あなたがthis libraryを使用することができ、追加

<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">  

    <com.github.rongi.rotate_layout.layout.RotateLayout 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     app:angle="-90"> <!-- Specify rotate angle here --> 

     <RelativeLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@android:color/holo_red_light"> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Hello World, I'm rotated now!" /> 
     </RelativeLayout> 

    </com.github.rongi.rotate_layout.layout.RotateLayout> 

</RelativeLayout> 

結果:

Result

関連する問題