如何在 LinearLayout 中旋转 textView?
how to rotate textView in 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
,并将 View
的 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);
//...
}
我想在我的项目中旋转 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
,并将 View
的 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);
//...
}