Use DIffent Font and Size.
2012-08-05 20:18
232 查看
================================
Download project link : http://ishare.iask.sina.com.cn/f/33394396.html
included files are:
result_1.png
result_2.png
result_3.png
result_4.png
test.Typefac.apk
test.Typefac.zip( source code )
Use DIffent Font and Size.docx
================================
(1)SIZE : To change the size of TextView ,we just need to find the object and call the method : .setTextSize(int) to do this task .
○But we here we add a function to it : let the size From 12 TO 29 and then From 29 to 12 , and so on .
if( flagSize <30 && flagSizeDEC == 0 )
{
tv.setTextSize(flagSize);
String size =String.valueOf(flagSize);
tv.setText( "Change me if you can ! " +" " + size);
flagSize++ ;
if(flagSize == 30)
{
flagSizeDEC = 1 ;
}
}
if( flagSize >12 && flagSizeDEC == 1 )
{
tv.setTextSize(flagSize);
flagSize-- ;
String size =String.valueOf(flagSize);
tv.setText( "Change me if you can ! " +" " + size);
if(flagSize == 12)
{
flagSizeDEC = 0 ;
}
}
(2)Font : to change the font of text, we need to call the
method : .setTypeface(tf)
[b]█the key point is to create a Typeface object. It can be done below : [/b]
tv.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/HandmadeTypewriter.ttf"));
Now we see how it was created:
FIRST STEP :
We can write:
tv.setTypeface(tf);
█ the question how to create Typeface ?
We goto the TextView reference and find the setTypeface Method ,Click the Typeface Link.
SECOND STEP:
In the Methods of Typeface reference , we see several Methods which return parameter are Typeface.
the simple way to created it are :
** *creatFromFile(String path).
***creatFromFile(File path).
*** creatFromAsset(AssetManager, String )
THIRD STEP:
Try to use the first and second methods ,but Failed.
/* Method 1
* BELOW CANNOT RUN.
String path = "/assets/fonts/BOCBI.ttf";
tv.setTypeface(Typeface.createFromFile(path));
*/
/*Method 2
*BELOW CANTOT RUN.
String path = "fonts/BOCBI.ttf";
File file = new File(path);
tv.setTypeface(Typeface.createFromFile(file));
*/
So we choose the third method.
When we goto the referance , we noticed :
The path parameter is in the assets dirctory ,DOES IT MEAN THAT THE PATH IN THE METHORD ABOVE IS IN THE SDCARD?
Fourth STEP:
After upload the font file “BOCIB.ttf” to the sdcard ,and then changed the path to :
“String path = "/mnt/sdcard/BOCBI.ttf";”
the first and second methods can run normally .
/*Method ONE, the font file is upload to "sdcard/BOCBI.ttf" */
String pathA = "/mnt/sdcard/BOCBI.ttf";
tv.setTypeface(Typeface.createFromFile(pathA));
/*Method TWO, upload file to "sdcard/HandmadeTypewriter.ttf " as same.*/
String pathB = "/mnt/sdcard/HandmadeTypewriter.ttf";
File file = new File(pathB);
tv.setTypeface(Typeface.createFromFile(file));
Further Step
Now we have solve the prolem , but how to use the third method ? we take a further step on the THIRD STEP .
We can write below using the third method:
tv.setTypeface(Typeface.createFromAsset( AssetManager mgr , String path ));
when we goto the referance page of AssetManager , it turned out that no method have a return parameter which is AssetManager. So how to get an AssetManager ?
So we have to search the web, the result is using method “getAssets()” of context , we can get an instance of our package.
So we can write it complete as follow :
/*Method THREE, the font fiel is in assets/fonts/tahoma.ttf */
String pathC = "fonts/tahoma.ttf" ;
tv.setTypeface(Typeface.createFromAsset(getAssets(), pathC));
Now we complete this project.
Download project link : http://ishare.iask.sina.com.cn/f/33394396.html
included files are:
result_1.png
result_2.png
result_3.png
result_4.png
test.Typefac.apk
test.Typefac.zip( source code )
Use DIffent Font and Size.docx
================================
(1)SIZE : To change the size of TextView ,we just need to find the object and call the method : .setTextSize(int) to do this task .
○But we here we add a function to it : let the size From 12 TO 29 and then From 29 to 12 , and so on .
if( flagSize <30 && flagSizeDEC == 0 )
{
tv.setTextSize(flagSize);
String size =String.valueOf(flagSize);
tv.setText( "Change me if you can ! " +" " + size);
flagSize++ ;
if(flagSize == 30)
{
flagSizeDEC = 1 ;
}
}
if( flagSize >12 && flagSizeDEC == 1 )
{
tv.setTextSize(flagSize);
flagSize-- ;
String size =String.valueOf(flagSize);
tv.setText( "Change me if you can ! " +" " + size);
if(flagSize == 12)
{
flagSizeDEC = 0 ;
}
}
(2)Font : to change the font of text, we need to call the
method : .setTypeface(tf)
[b]█the key point is to create a Typeface object. It can be done below : [/b]
tv.setTypeface(Typeface.createFromAsset(getAssets(), "fonts/HandmadeTypewriter.ttf"));
Now we see how it was created:
FIRST STEP :
We can write:
tv.setTypeface(tf);
█ the question how to create Typeface ?
We goto the TextView reference and find the setTypeface Method ,Click the Typeface Link.
SECOND STEP:
In the Methods of Typeface reference , we see several Methods which return parameter are Typeface.
the simple way to created it are :
** *creatFromFile(String path).
***creatFromFile(File path).
*** creatFromAsset(AssetManager, String )
THIRD STEP:
Try to use the first and second methods ,but Failed.
/* Method 1
* BELOW CANNOT RUN.
String path = "/assets/fonts/BOCBI.ttf";
tv.setTypeface(Typeface.createFromFile(path));
*/
/*Method 2
*BELOW CANTOT RUN.
String path = "fonts/BOCBI.ttf";
File file = new File(path);
tv.setTypeface(Typeface.createFromFile(file));
*/
So we choose the third method.
When we goto the referance , we noticed :
The path parameter is in the assets dirctory ,DOES IT MEAN THAT THE PATH IN THE METHORD ABOVE IS IN THE SDCARD?
Fourth STEP:
After upload the font file “BOCIB.ttf” to the sdcard ,and then changed the path to :
“String path = "/mnt/sdcard/BOCBI.ttf";”
the first and second methods can run normally .
/*Method ONE, the font file is upload to "sdcard/BOCBI.ttf" */
String pathA = "/mnt/sdcard/BOCBI.ttf";
tv.setTypeface(Typeface.createFromFile(pathA));
/*Method TWO, upload file to "sdcard/HandmadeTypewriter.ttf " as same.*/
String pathB = "/mnt/sdcard/HandmadeTypewriter.ttf";
File file = new File(pathB);
tv.setTypeface(Typeface.createFromFile(file));
Further Step
Now we have solve the prolem , but how to use the third method ? we take a further step on the THIRD STEP .
We can write below using the third method:
tv.setTypeface(Typeface.createFromAsset( AssetManager mgr , String path ));
when we goto the referance page of AssetManager , it turned out that no method have a return parameter which is AssetManager. So how to get an AssetManager ?
So we have to search the web, the result is using method “getAssets()” of context , we can get an instance of our package.
So we can write it complete as follow :
/*Method THREE, the font fiel is in assets/fonts/tahoma.ttf */
String pathC = "fonts/tahoma.ttf" ;
tv.setTypeface(Typeface.createFromAsset(getAssets(), pathC));
Now we complete this project.
相关文章推荐
- EditBox Control and font size
- Set font size and color in GUI.Label
- SQL Server, Timeout expired.all pooled connections were in use and max pool size was reached
- sizeWithFont:constrainedToSize:' is deprecated: first deprecated in iOS 7.0 - Use -boundingRectWithS
- Calculating The Logical Height and Point Size of a Font
- 'sizeWithFont:' is deprecated: first deprecated in iOS 7.0 - Use -sizeWithAttributes:
- Logback (6) | SizeAndTimeBasedFNATP is deprecated. Use SizeAndTimeBasedRollingPolicy instead
- INFO: Font Metrics and the Use of Negative lfHeight
- Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached.
- Unity3D GUISkin Font(ttf) 导致的:“Font size and style overrides are only supported for dynamic fonts.
- Setting Text to Image On Android and Adjudt the text font size based on the android resolution
- Its width is W and height is H. As a result, if the font size of characters is S then it can only sh
- Calculating The Logical Height and Point Size of a Font
- When should we use PUT and when should we use POST?
- 不能用 字体大小(font-size) + padding 计算元素的高度
- (Page 2 of 3 )A walking tour of JavaBeans 2 :What JavaBeans is, how it works, and why you want to use it
- Use cp and mv carefully on Solaris.
- How to configure and use CAN bus
- MAC 字体创建和储存(来自于CoreText翻译 Font Creation and Storage)(一)