自定義豎直旋轉顯示文字的TextView

2021-07-30 08:37:52 字數 1805 閱讀 1408

先看效果(最右邊的buttons):

原理很簡單,就是使用了drawtextonpath()沿著一條垂直的直線繪製文字,該直線可以從上往下或者從下往上,通過direction屬性控制文字顯示的方向。該類是本人要處理垂直顯示英文本的時候逼出來的,呵呵;如果是中文字就簡單了,直接加個換行符就滿足要求了。

這下可以滿足了吧?!(老外通常比較深~~~)

原始碼:

package com.reyo.view;

import android.content.context;

import android.content.res.typedarray;

import android.graphics.canvas;

import android.graphics.paint.align;

import android.graphics.path;

import android.graphics.rect;

import android.text.textpaint;

import android.util.attributeset;

import android.view.view;

import com.reyo.goingdishes.r;

public class verticaltextview extends view

public verticaltextview(context context, attributeset attrs)

private final void init()

public void settext(string text)

public void settextsize(int size)

public void settextcolor(int color)

@override

protected void onmeasure(int widthmeasurespec, int heightmeasurespec)

private int measurewidth(int measurespec) else

}return result;

}private int measureheight(int measurespec) else

}return result;

}@override

protected void ondraw(canvas canvas) else

canvas.drawtextonpath(mtext, path, 0, 0, mtextpaint);}}

自定義屬性attr.xml:

用法:

android:id="@+id/btn_1"

android:layout_width="match_parent"

android:layout_height="@dimen/main_btn_height"

android:background="@drawable/bg_btn_order"

android:layout_marginright="5dp"

android:layout_margintop="5dp"

android:layout_marginbottom="5dp"

android:clickable="true"

android:focusable="true"

android:tag="1"

/>

大小: 704.6 kb

C 自定義MessageBox 按鈕的Text

using system using system.drawing using system.runtime.interopservices using system.text using system.windows.forms namespace sphinx.utils public stat...

android開發之自定義帶邊框的TextView

自定義帶邊框的textview activity package cn.class3g.activity import android.content.context import android.graphics.canvas import android.graphics.paint impor...

css自定義文字

第一步 獲取要使用字型的三種檔案格式,確保能在主流的瀏覽器中都能正常顯示改字型,並使用fonteditor檢視字型內容。1 ttf或.otf,適用於firefox3.5 safari opera。2 eot,適用於internet explorer 4.0 3 svg,適用於chrome iphon...