【问题标题】:android rotated TextView inherits the parent's widthandroid旋转的TextView继承父级的宽度
【发布时间】:2018-11-05 20:17:34
【问题描述】:

我想将 TextView 旋转 -90 或 270 度,并让结果的总宽度等于 TextView 的高度。这是我的模型:

我将我的 TextView 设为 120dp x 20dp。

我将它插入到父容器(RelativeLayout 或任何)中。

我在 XML 中将它旋转 -90 度,但是当我将其父级设置为 20dp 宽度时,TextView 也会继承此宽度,因此它会剪切我的文本(对于父级,clipChildren 设置为 false 无效)。

TextView 应该是动态的,它应该随着当月每次更新,我不想为此使用背景可绘制对象。

【问题讨论】:

    标签: java android xml android-layout layout


    【解决方案1】:

    好吧,在网上搜索了几个小时但没有任何结果或有人为此编写课程后,在发布问题仅 30 分钟后,我设法实现了我想要的。

    我将 TextView 放在 FrameLayout 中,现在它不会继承其父宽度。还给了它一个正方形的比例和一个layout_gravity,代码如下:

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="20dp"
        android:layout_height="wrap_content">
    
        <TextView
            android:id="@+id/text"
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:rotation="-90"
            android:text="january"
            android:textSize="14sp"
            android:gravity="center|right"
            android:layout_gravity="top|center"
            android:paddingRight="8dp"
            android:background="@color/itemMainBgColor"/>
    
    </FrameLayout>
    

    【讨论】:

    • 该死的解决方法!...感谢分享。
    猜你喜欢
    • 1970-01-01
    • 2015-03-25
    • 1970-01-01
    • 1970-01-01
    • 2013-09-12
    • 1970-01-01
    • 1970-01-01
    • 2018-08-07
    • 2015-03-14
    相关资源
    最近更新 更多