Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/199.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何将旋转布局向右对齐并匹配父级高度?_Android_Android Layout_Android Relativelayout_Android Xml_Android Layoutparams - Fatal编程技术网

Android 如何将旋转布局向右对齐并匹配父级高度?

Android 如何将旋转布局向右对齐并匹配父级高度?,android,android-layout,android-relativelayout,android-xml,android-layoutparams,Android,Android Layout,Android Relativelayout,Android Xml,Android Layoutparams,我将创建一个在右边有状态栏的布局 我尝试使用xml,但这不起作用,条形图无法向右对齐,旋转后textview不在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"

我将创建一个在右边有状态栏的布局

我尝试使用xml,但这不起作用,条形图无法向右对齐,旋转后textview不在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>
如何将条宽设置为与屏幕高度相同?

您可以使用,添加:

并格式化您的布局:

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

结果:


伙计,红色视图只需宽度,因为当它水平时,它需要填充父对象,如果旋转90°c,它需要相同的高度(我的意思是它从高度获取宽度大小),默认情况下,Android使用视图的中点作为轴心旋转。您可以使用
transformPivotX
transformPivotY
来避免手动旋转。然而,也许研究一些垂直文本视图实现是一种替代旋转的方法。
RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(1920, h);
topBarLand.setLayoutParams(param);
dependencies {
    compile 'rongi.rotate-layout:rotate-layout:2.0.0'
}
<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>