Reputation: 693
I am using the typeface in my text view and it is all looking good. Now I want to set the seekbar which will help the user to adjust the text size under the text view.
I have just used the seekbar and played with it. this is how I am using my Seekbar to make the text larger
/// SeekBar Progress
sk.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
int p=0;
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
if(p<30)
{
p=30;
sk.setProgress(p);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
// TODO Auto-generated method stub
p=progress;
myTextView.setTextSize(p);
}
});
this is working and changing the size of text in the text view, But now there comes the problem :
Problem :
Problem is , the size is increasing and decreasing also when we take the seek bar to the left from its mid point. where as I want to set the minimum and maximum value. So to set the minimum and maximum I need to get the size of text inside the text view . and I have not found any method to get the textsize like for example myTextview.getTextSize() , there is no such method like it.
Let me tell you I am setting the size of the text view from the dimens file in the different values folder for supporting all the device and to make my text look good on tablets and small devices.
So now All I need to get is My text size inside the Text view . Please help me in getting the text size. thank you.
Upvotes: 3
Views: 9775
Reputation: 693
I think the simplest answer is
myTextView.getTextSize();
Actually I was casting my value wrong. and Now it is solved. after doing this
float size = myTextView.getTextSize();
Upvotes: 1
Reputation: 60081
Do check that your myTextView
is indeed TextView
and not just View
when you initialize it. e.g.
TextView myTextView = (TextView) findViewById(yourTextViewId);
Upvotes: 1
Reputation: 345
There is TextView.getTextSize()
. You can also go TextView.getPaint().getTextSize()
.
Upvotes: 3
Reputation: 1977
try this
text_one.setText("your text");
text_one.measure(0, 0); //must call measure!
text_one.getMeasuredHeight(); //get height
text_one.getMeasuredWidth();
Upvotes: 1