1

오른쪽에 상태 표시 줄이있는 레이아웃을 만들 예정입니다.회전 된 레이아웃을 오른쪽으로 정렬하고 부모 높이를 맞추는 방법은 무엇입니까?

xml을 사용하려고했으나 작동하지 않으며 바가 오른쪽으로 정렬되지 않고 텍스트보기가 회전 후 relativelayout에 없습니다.

enter image description here

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

그러나 바의 폭이 화면의 높이를 일치하지 않을 수는

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

관련 문제