I am trying to create something like the following using LinearLayout and TableLayout:
None of the solutions worked for me but I found this blog post by Mark Allison: https://blog.stylingandroid.com/verticaltext-part-1/
public class VerticalTextView extends TextView
{
final boolean topDown;
public VerticalTextView( Context context,
AttributeSet attrs )
{
super( context, attrs );
final int gravity = getGravity();
if ( Gravity.isVertical( gravity )
&& ( gravity & Gravity.VERTICAL_GRAVITY_MASK )
== Gravity.BOTTOM )
{
setGravity(
( gravity & Gravity.HORIZONTAL_GRAVITY_MASK )
| Gravity.TOP );
topDown = false;
}
else
{
topDown = true;
}
}
@Override
protected void onMeasure( int widthMeasureSpec,
int heightMeasureSpec )
{
super.onMeasure( heightMeasureSpec,
widthMeasureSpec );
setMeasuredDimension( getMeasuredHeight(),
getMeasuredWidth() );
}
@Override
protected void onDraw( Canvas canvas )
{
TextPaint textPaint = getPaint();
textPaint.setColor( getCurrentTextColor() );
textPaint.drawableState = getDrawableState();
canvas.save();
if ( topDown )
{
canvas.translate( getWidth(), 0 );
canvas.rotate( 90 );
}
else
{
canvas.translate( 0, getHeight() );
canvas.rotate( -90 );
}
canvas.translate( getCompoundPaddingLeft(),
getExtendedPaddingTop() );
getLayout().draw( canvas );
canvas.restore();
}
}
The rotation is done by the gravity. So be sure to set this in your xml:
<com.stylingandroid.verticaltext.VerticalTextView
style="@style/verticalTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="bottom|right"
android:text="@string/text" />
If you want to reproduce your image I would use a GridView or a TableLayout with no buttons, just set the proper listeners if you need to do any action. This way you can set fixed heights and widths.
Put all the Text view in Linear Layout and try to give proper Layout weight to solve your problem
Here is a hack to create vertical text view. So the scenario was I need to show a static tag on the right side of the screen. so I just used "\n" for the new line as my text was less.
android:text="A\nC\nT\nI\nO\nN"
You can check the image I've attached. although it's not suggested if you showing data from Dynamically.
<TextView
android:id="@+id/tv_action"
android:layout_width="20dp"
android:layout_height="126dp"
android:background="@drawable/bg_red_left_rcorner"
android:gravity="center"
android:padding="2dp"
android:textStyle="bold"
android:text="A\nC\nT\nI\nO\nN"
android:textColor="@color/white"
app:layout_anchor="@+id/drawer_layout"
app:layout_anchorGravity="end|center" />
in .xml file just put
<TextView>
android:layout_width="wrap content"
android:layout_height="wrap content"
android:rotation="270"
</TextView>