Android中的垂直Textview

时间:2016-06-11 17:52:42

标签: android textview

我有我的屏幕,它在4个部分中垂直划分,我想在所有4个条带中使用垂直文本,我尝试使用android:rotation="-90"但是如果我的文本很长,它会出现在2行中。我怎样才能在一行中制作它。

我想要DELHI AGRA专线

enter image description here

以下是我的xml布局

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false"
        android:weightSum="4"
        android:layout_below="@+id/offers_view">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@+id/first"
            android:background="#CC4D9E59"
            android:layout_weight="1"
            android:weightSum="1">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/one"
                android:text="Delhi Agra"
                android:textSize="@dimen/textsize_xxxmedium"
                android:textColor="@color/white"
                android:textAllCaps="true"
                android:rotation="-90"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@+id/second"
            android:background="#CC9C27B0"
            android:layout_weight="1">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:text="Goa"
                android:id="@+id/two"
                android:textSize="@dimen/textsize_xxxmedium"
                android:textColor="@color/white"
                android:textAllCaps="true"
                android:gravity="center"
                android:rotation="-90"
                android:layout_gravity="bottom|center_vertical"
                android:layout_marginBottom="@dimen/margin_lmedium"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@+id/third"
            android:background="#CC2196F3"
            android:layout_weight="1">

            <TextView
                android:layout_width="85dp"
                android:layout_height="match_parent"
                android:id="@+id/three"
                android:text="Delhi"
                android:textSize="@dimen/textsize_xxxmedium"
                android:textColor="@color/white"
                android:textAllCaps="true"
                android:gravity="center"
                android:rotation="-90"
                android:layout_gravity="top|center_horizontal"
                android:layout_marginTop="@dimen/margin_lmedium"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@+id/fourth"
            android:background="#CCFF9800"
            android:layout_weight="1">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:id="@+id/view_all_cities"
                android:text="@string/view_all_cities"
                android:textSize="@dimen/textsize_xxxmedium"
                android:textColor="@color/white"
                android:textAllCaps="true"
                android:rotation="-90"
                android:gravity="center"
                android:layout_gravity="center_vertical"
                android:layout_marginTop="@dimen/margin_lmedium"/>

        </LinearLayout>

    </LinearLayout>

1 个答案:

答案 0 :(得分:1)

最后我开始工作了

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:baselineAligned="false"
        android:weightSum="4"
        android:layout_below="@+id/offers_view">

        <com.example.app.views.VerticalTextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:id="@+id/one"
            android:text="Delhi Agra"
            android:textSize="@dimen/textsize_large"
            android:textColor="@color/white"
            android:textAllCaps="true"
            android:layout_weight="1"
            android:background="#CC4D9E59"
            android:layout_gravity="center"
            android:gravity="right|center_horizontal"
            android:paddingRight="@dimen/margin_lmedium"/>

        <com.example.app.views.VerticalTextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="Goa"
            android:id="@+id/two"
            android:textSize="@dimen/textsize_large"
            android:textColor="@color/white"
            android:textAllCaps="true"
            android:background="#CC9C27B0"
            android:layout_weight="1"
            android:gravity="left|center_horizontal"
            android:paddingLeft="@dimen/logo_size"/>

        <com.example.app.views.VerticalTextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:id="@+id/three"
            android:text="Delhi"
            android:textSize="@dimen/textsize_large"
            android:textColor="@color/white"
            android:textAllCaps="true"
            android:background="#CC2196F3"
            android:layout_weight="1"
            android:layout_gravity="center_horizontal"
            android:gravity="right|center_horizontal"
            android:paddingRight="@dimen/margin_lmedium"/>

        <com.example.app.views.VerticalTextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:id="@+id/view_all_cities"
            android:clickable="true"
            android:text="@string/view_all_cities"
            android:textSize="@dimen/textsize_large"
            android:textColor="@color/white"
            android:textAllCaps="true"
            android:background="#CCFF9800"
            android:layout_weight="1"
            android:layout_gravity="center_horizontal"
            android:gravity="center_horizontal" />

    </LinearLayout>

VerticalTextView Vertical (rotated) label in Android

进行此操作