我想在我的项目中旋转 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);
//...
}
关于android - 如何在 LinearLayout 中旋转 textView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29769947/