美文网首页
拼音汉字上下结构sundarPinyinText

拼音汉字上下结构sundarPinyinText

作者: 冯员外_SundarFung | 来源:发表于2017-03-17 09:30 被阅读0次

由于项目需要,做上拼音下汉字的View结构,找了很多开源,合适的很少,后来自己根据其中一个pinyin-text-view对其做了修正已经做了进一步的优化与扩展,然后自己按耐不住发了一版。可以说现在非常简单易用容易上手

SundarPinyinText的GitHub地址 顺便给个星哇

直接上效果图

1.0.6_1.jpg

Gradle:

Step 1.

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2.

dependencies {
      compile 'com.github.SundarFung:sundarPinyinText:1.0.7'
            }

maven:

Step 1.

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Step 2.

<dependency>
    <groupId>com.github.SundarFung</groupId>
    <artifactId>sundarPinyinText</artifactId>
    <version>1.0.7</version>
</dependency>

使用方法

<com.sundar.sundarpinyintext.PinyinText
    android:id="@+id/textPT"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="28dp"
    android:layout_centerHorizontal="true"
    />


   String pinyinText="#yǒng#yuǎn# #Shēngrì# # #yǒng#yuǎn# #Shēngrì# # #yǒng#yuǎn# #Shēngrì# #";
        String chineseText="#永#远# ____ 。#生日# ____!# #永#远# ____ 。#生日# ____!# #永#远# ____ 。#生日# ____!#";
        String chineseNorText="生日生日生日生日";
        String pinyinNorText="ShēngrìShēngrìShēngrì";
        List<Pair<String, String>> pairList = new ArrayList<>();
        String[] mChinese = chineseText.split("\\#");
        String[] mPinyin = pinyinText.split("\\#");
        for (int i = 0; i < mChinese.length; i++) {
            if (i < mPinyin.length) {
                pairList.add(Pair.create("" + mChinese[i], "" + mPinyin[i]));
            }
        }
//汉字
    textPT.setText(chineseNorText);
    textPT.setTextColor(0xefef6688);//颜色是8位16进制
    //汉字带字体
    text_ttf.setText(chineseNorText,"mengmengda.ttf");//设置非拼音汉字结构的字体
    //拼音
    pinyinPT.setText(pinyinNorText);
    //拼音带字体
    pinyin_ttf.setText(pinyinNorText,"mengmengda.ttf");
    pinyin_ttf.setTextColor(0x88FF9912);
    pinyin_ttf.setTextSize(60);
    //普通的拼音汉字结构
    pinyinTextPT.setPinyinText(pairList);
    //普通带间距
    pinyinTextPT1.setPinyinText(pairList);
    pinyinTextPT1.setTextSize(50);//汉字的大小
    pinyinTextPT1.setVerticalSpacing(60);//每行字之间的距离(字多换行间)
    pinyinTextPT1.setHorizontalSpacing(100);//横向每个字之间的距离
    //普通的拼音汉字结构带字体,字体限制只对拼音有效
    pinyinText_ttf.setPinyinText(pairList,"mengmengda.ttf");//设置上下结构的拼音字体
    pinyinText_ttf.setPinyinTextColor(0x889933FA);
    pinyinText_ttf.setPinyinTextSize(50);//拼音的大小
    pinyinText_ttf.setLineSpacing(20);//拼音和汉字之间的距离(默认是行距的一半)

sundarfung.me

相关文章

网友评论

      本文标题:拼音汉字上下结构sundarPinyinText

      本文链接:https://www.haomeiwen.com/subject/ykndnttx.html