6

(私の貧しい質問で申し訳ありません。私は今それを更新しました)

XMLファイルで作成するにはどうすればよいですか?次のコードを使用しようとしましたが、正しくありませんでした (「android:rotation="-90」を使用して回転させました。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<FrameLayout
    android:layout_width="141dp"
    android:layout_height="200dp"
    android:layout_weight="0.41"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/sidebar_title"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/shape_card_sidebar"
        android:inputType="text"
        android:rotation="-90"
        android:text="I want to be like this" >
    </EditText>
</FrameLayout>

ここに画像の説明を入力

4

2 に答える 2

2

そんなことをしようとすると、さまざまな問題が発生します。最も明白な問題は、誤った測定です。代わりに、カスタム ビューを作成する必要があります。このようなもの:

public class RotatedTextVew extends TextView {
    public RotatedTextView(Context context) {
        super(context);
    }

    public RotatedTextView(Context context, AttributeSet attrs) {
        super(context, attrs)
    }

    public RotatedTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // Switch dimensions
        super.onMeasure(heightMeasureSpec, widthMeasureSpec);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        canvas.save();
        canvas.rotate(90);
        super.onDraw(canvas);
        canvas.restore();
    }
}

私は実際にこれをテストしていませんが、これが私が始める方法です。

于 2013-04-22T18:49:02.857 に答える