繁体   English   中英

android旋转TextView继承父级宽度

[英]android rotated TextView inherits the parent's width

我想将 TextView 旋转 -90 或 270 度,并使生成的总宽度等于 TextView 高度。 这是我的样机:

在此处输入图片说明

我使我的 TextView 为120dp x 20dp

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

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

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

好吧,经过几个小时的网络搜索但没有结果,或者有人写课程来做到这一点,并且在发布问题后仅 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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM