How to make text in EditText vertically (Android)

(Sorry for my bad question. I updated it now)

How can I do this in an XML file? I tried using the following code, but not correctly (I used "android: rotation =" - 90 "to rotate.

<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> 

enter image description here

+6
source share
2 answers

You will have problems if you try to do this. The most obvious problem will be a wrong measurement. Instead, you should create your own view. Something like that:

 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(); } } 

I really have not tested this, but here is how I started.

+2
source

Replace FrameLayout and LinearLayout . Also set the android: gravity = "center" property of the parent layout.

0
source

All Articles