之前寫過一篇關於字型苗邊的文章:
Android
引入自體庫 改變字型樣式(給字型描邊),但是效果不好。
現在介紹一種新的方法。
基本思路和之前一樣,都是兩個TextView疊在一起,兩者字型大小一樣,
而下面的字型粗一些。之前是直接設定的粗體,現在通過改變畫筆的粗細
來實現,效果好多了,先看效果:
代碼很簡單:
layout布局檔案:<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/hello"android:textSize="50sp"android:textColor="#42979f"android:id="@+id/tvBack"android:shadowColor="#42979f"android:shadowDx="2"android:shadowDy="2"android:shadowRadius="5"/><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/hello"android:textSize="50sp"android:textColor="#ffffff"/></RelativeLayout>
.java檔案
Paint paint = ((TextView) findViewById(R.id.tvBack)).getPaint();
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(8);
需要注意的是,paint.setStrokeWidth()起作用的前提是paint.setStyle(Paint.Style.STROKE);(字型空心),另外為了使字型
看起來更立體,我加了陰影製作效果:
android:shadowColor="#42979f"android:shadowDx="2"android:shadowDy="2"android:shadowRadius="5"
此條目發表在
Android開發 分類目錄,貼了
Android 字型苗邊, android,bitmap,matrix,
Paint,
paint 加粗,
paint 苗邊,
paint.setStrokeWidth,
paint.setStyle(Paint.Style.STROKE),
TextView,
TextView 苗邊,
字型加粗,
字型苗邊,
易網聯信 標籤。將固定連結加入收藏夾。← 速寫作品2SurfaceView (更加適合遊戲開發) Callback以及SurfaceHolder詳解
→《
Android 給字型苗邊》有 1 條評論
-
Pingback 引用:
自訂控制項 –百科專家總結 | 易網聯信