Comments (19)
sorry i have not add customizing font function, you can custom font in NumberPickerView by using code:
mPaintText.setTypeFace(...);
when mPaintText
is initialized.
i will add this function later
from numberpickerview.
Thanks, for fast answer.
I try to edit the file within Android Studio but I can't edit the file. It's locked :(
Any Idea about this?
from numberpickerview.
After some search, I manage to import the project as module and was able to edit the file but what I should put in mPaintText.setTypeFace(...);
?
I tried those but didn't work:
mPaintText.setTypeface(Typeface.create("2Toon", Typeface.BOLD)); mPaintText.Typeface.createFromAsset(getContext().getAssets(), "2Toon.ttf"); mPaintText.setTypeface(Typeface.createFromAsset(getContext().getAssets(),"fonts/2Toon"));
from numberpickerview.
sorry for not replying in time, you can add a method
public void setContentTextTypeface(Typeface typeface){
mPaintText.setTypeface(typeface);
}
public void setHintTextTypeface(Typeface typeface){
mPaintHint.setTypeface(typeface);
}
and invoke this method outside in oncreate method , if you want to change typeface dynamicly, using mNumberPickerView.invalidate( ) after using this method
from numberpickerview.
No Problem :)
I solved the problem by adding:
mPaintText.setTypeface(Typeface.createFromAsset(context.getAssets(),"fonts/MyFont.ttf"));
It worked for me. I don't know if it's a good practice to do it in that way though.
from numberpickerview.
if you have used MyFont.ttf, you can use a static value to refer to this MyFont.ttf, in this way you can avoid memory leak, because every time you use
Typeface.createFromAsset(context.getAssets(),"fonts/MyFont.ttf")
MyFont.ttf will be created again and added into memory.
from numberpickerview.
I don't understand what you mean by "...use a static value to refer to this MyFont.ttf".
How can I use a static value to refer to the custom font I want use?
from numberpickerview.
i mean you can use cache to refer to MyFont.ttf, in this way, if you use MyFont.ttf again, you can get MyFont.ttf from cache,
just like
public static Typeface cache = Typeface.createFromAsset(context.getAssets(),"fonts/MyFont.ttf")
mPaintText.setTypeface(cache);
this will avoid memory leak
from numberpickerview.
Ah okay, I got it now. I'll change it.
But compared to [your solution], what are the differences/advantages?(#17 (comment))
from numberpickerview.
if there are many numberpickerviews in you app( or other views which use MyFont.ttf), there will be many copy of MyFont.ttf, but in fact only one MyFont.ttf is enough
from numberpickerview.
Cool, I got it :) Thank you very much.
Off Topic:
Is their a way to display the selected numbers while scrolling?
I tried to put it in the the onScrollStateChange
methode but it randomly crash my app.
Like in this gif:
http://i.imgur.com/d3ZMjss.gif
from numberpickerview.
i have not add this function, if you need this function now, you can add some code into
calculateFirstItemParameterByGlobalY()
and get the index of current selected item by mCurrDrawFirstItemIndex
and mCurrDrawFirstItemY
, and set this index value to another value such as 'currSelected', and use a 'prevSelected' to store the last selected one in scrolling, if currSelected != prevSelected, then number changed. i will add this function later :)
from numberpickerview.
i have added a method
picker.setOnValueChangeListenerInScrolling(...);
you can get changed value while in scrolling
and i have also added two methods for changing typeface of text/hint in NumberPickerView,
just update dependence version of NumberPickerView to 1.1.1
from numberpickerview.
Oh, Great,
I just try it , it's working but the scrolling is not smooth. It lags a lot.
`
@Override
public void onValueChangeInScrolling(NumberPickerView picker, int oldVal, int newVal) {
myChosedNumber.setText(picker.getContentByCurrValue());
}
`
Is there a better way to make it as smooth as in the gif
from numberpickerview.
this callback will be invoked once as number value changed for 'one item', and this callback runs in main thread , if you want to do some complicated work in this callback such as play sound, it may make scrolling lag. To make scrolling smoothly you can use handler to send message in this callback ,or make callback tasks run in a new thread, if it still lag, you can send your code to me ,and maybe i can refine this project according to your code
from numberpickerview.
Hi, I sent just you the project via email,
I've tried to put the code in a Runnable
as well in a AsyncTask
but it was still laggy.
I planned to add a scrolling sound but It's not much of a big deal if it may create (lag) problems...
If you need any info, let me know.
from numberpickerview.
And by the way, I've try the project in that gif on my phone and it was working smoothly, just like in the gif.
I found that project from here, Just in case it may help.
from numberpickerview.
@Carbs0126 Can you update the version in the README file to 1.1.1?
I was trying to branch the repo to add the Typeface functionality, but saw that it was already implemented in this version (which is not refereed to anywhere).
from numberpickerview.
I have created a fork of the project which allows custom font loading from xml itself. I will be glad if you can take a look at it.
https://github.com/rohankandwal/NumberPickerView
from numberpickerview.
Related Issues (20)
- 什么情况下会导致这个问题呢?getWillPickIndexByGlobalY illegal index : 178 getOneRecycleSize() : 171 mWrapSelectorWheel : false HOT 1
- 两个NumberPickerView做联动并且第二个滚动并快速点击有个问题 HOT 3
- 设置纯数字1-999奔溃 HOT 2
- How to add sound when scroll or selected like ios HOT 3
- 该如何设置取消两端选项的缩放效果呢? HOT 2
- 有个BUG请关注下 HOT 6
- BUG HOT 2
- 文字可以定义垂直显示样式 HOT 3
- 大佬,能设置数字小于10时,十位补0显示吗? HOT 2
- 請問有設定字體大小的Function嗎,像是SetTextSizeNormal() HOT 1
- 您好,最新的1.2.0版本有个Bug HOT 7
- should not be greater than mDisplayedValues.length now
- 偶现 getWillPickIndexByGlobalY illegal index : 2 getOneRecycleSize() : 2 mWrapSelectorWheel : true
- JCenter sunset is announced; please republish library version(s) to Maven Central HOT 2
- jcenter跑路了,能把项目同步到 mavenCentral 或者 jitpack 上吗 HOT 1
- np_textAlign doesn't do anything
- 必现错误getWillPickIndexByGlobalY illegal index : 5 getOneRecycleSize() : 1 mWrapSelectorWheel : false HOT 1
- No fading effect to the edges
- 时常遇到getWillPickIndexByGlobalY 的 IllegalArgumentException
- Check number save accounts
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from numberpickerview.