Pinyin-text-view is a library to display pinyin and text to users.
Android 2.2+
-
If you are using
Android Studio
:
Add the following line to the dependencies section of yourbuild.gradle
file:compile 'com.uudove.lib:pinyin-text-view:X.X.X'
where
X.X.X
is the your preferred version. (Now there is no release, please use the source code) -
If you are using
Eclipse
:
Download the source code.
Define PinyinTextView
in layout xml. If you don't understand what are the attributes mean, see How this porject is designed
<com.uudove.pinyin.widget.PinyinTextView
android:id="@+id/pinyin_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#e0e0e0"
android:horizontalSpacing="10dp"
android:textColor="#000000"
android:textColorHint="#666666"
android:textSize="20sp"
android:verticalSpacing="10dp" />
Find PinyinTextView
in Activity or Fragment, and set the data to display.
mPinyinTextView = (PinyinTextView) findViewById(R.id.pinyin_text_view);
List<Pair<String, String>> pairList = new ArrayList<Pair<String, String>>();
pairList.add(Pair.create("你", "nǐ"));
pairList.add(Pair.create("在", "zài"));
pairList.add(Pair.create("哪", "nǎ"));
pairList.add(Pair.create("?", " "));
pairList.add(Pair.create("我", "wǒ"));
pairList.add(Pair.create("在", "zài"));
pairList.add(Pair.create("家", "jiā"));
pairList.add(Pair.create(",", " "));
pairList.add(Pair.create("很", "hěn"));
pairList.add(Pair.create("高", "gāo"));
pairList.add(Pair.create("兴", "xìng"));
pairList.add(Pair.create("认", "rèn"));
pairList.add(Pair.create("识", "shi"));
pairList.add(Pair.create("你", "nǐ"));
pairList.add(Pair.create("!", " "));
mPinyinTextView.setPinyinText(pairList);
The rects below is just for debug, they won't be drawn in release mode.
Copyright [uudove]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.