Android 給字型苗邊

來源:互聯網
上載者:User

之前寫過一篇關於字型苗邊的文章:

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 條評論
  1. Pingback 引用:
    自訂控制項 –百科專家總結 | 易網聯信

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.