android - 如何在 LinearLayout 中旋转 textView?

标签 android textview android-linearlayout

我想在我的项目中旋转 linearlayout 内的 textView。 但是旋转时只有一部分textView被淹没。

这是我的 xml。

    <LinearLayout 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignRight="@+id/Test"
    android:layout_below="@+id/Test"
    android:layout_marginTop="34dp"
    android:orientation="vertical"
    >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:rotation="90"
        android:text="TextView" />



</LinearLayout>

最佳答案

以编程方式设置 TextView 尺寸

我们应该找到包含在 View 中的显示文本的宽度,同时考虑到 Font,并设置 heigh查看到此。

protected void myMethod() {
    //...

    //Get component components paint and text
    TextView textView = (TextView) findViewById(R.id.textView1);
    String text = (String) textView.getText();
    Paint paint = textView.getPaint();

    //Calculate width of the string given the paint
    int width = (int) paint.measureText(text);

    //Set the minimum width of the component to the width of text contained
    textView.setMinimumHeight(width);

    //...
}

Example

关于android - 如何在 LinearLayout 中旋转 textView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29769947/

相关文章:

java - 运行 Activity 两次(而不是一次)以从 getter 获取值

android - LayoutParams Gravity Right 不强制执行

android - 为具有不同 TextSize 的 TextView 设置相同的高度

java - 如何将数据存储到数组以及从数组中求和数据

java - ZipInputStream 在提取 zip 文件之前检查它是否有效

android - 根据用户在配置 Activity 中的选择,在小部件中将 StateListDrawable 设置为 ImageButton/ImageView.backgroundDrawable

android - 想在 ListView 中的 TextView 中设置罢工

java - 如何让TextView完全忽略触摸?

android - ScrollView 不是从顶部开始

android - 从 ListView android中删除点击的项目