Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6108131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:15:49+00:00 2026-05-23T14:15:49+00:00

Here I put my code of 2 buttons. I have to face one problem.

  • 0

Here I put my code of 2 buttons.

I have to face one problem. Button works OK in MDPI view but I have a problem in the QVGA emulator.

In QVGA when I press the plus button then its size decreases y and when I press the minus button, no change occurs

if(v==im7)
{
    float size=tx3.getTextSize();
    float size1=tx2.getTextSize();

    Toast.makeText(this,"plus"+String.valueOf(size),2000).show();

    size=size+1;
    size1=size1+1;

    tx3.setTextSize(size);
    tx2.setTextSize(size1);                 
}

if(v==im8)
{
    /*float size=tx3.getTextSize();
    float size1=tx2.getTextSize();
    */
    Toast.makeText(this,"minus"+String.valueOf(size),2000).show();

    size=size-1;
    size1=size1-1;

    tx3.setTextSize(size);
    tx2.setTextSize(size1);         
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:15:50+00:00Added an answer on May 23, 2026 at 2:15 pm

    That will probably only work for mdpi screens. mdpi are the standard but ldpi and hdpi are scaled at 0.75% and 1.5% respectively.

    Try this:

    In your instance variables:

    private DisplayMetrics metrics;
    private int my_density;
    private TextView your_textview;
    

    In your onCreate, initialize your variables and find your view and set its onclicklistner (make sure to implement OnClickListener):

    your_textview = (TextView)findViewById(R.id.txt_your_textview);
    your_textview.setOnClickListener(this);
    metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    my_density = metrics.densityDpi;
    

    Then the tricky part:

    Depending on the screen density you need to scale the size you give setTextSize() accordingly. Really setTextSize() should take care of this but it doesn’t. Use the method below as an example of how to increase the text for your TextView.

    private void increaseFontSize(){
            float size = your_textview.getTextSize();
            int max_size = 30; //define your own max here
            if(size<=max_size){
                switch(my_density){
                case DisplayMetrics.DENSITY_LOW:
                    size = (your_textview.getTextSize()+2) / 0.75f;
                    break;
    
                case DisplayMetrics.DENSITY_MEDIUM:
                    size = your_textview.getTextSize()+2;
                    break;
    
                case DisplayMetrics.DENSITY_HIGH:
                    size = (your_textview.getTextSize()+2) / 1.5f;
                    break;
    
                default:
                    break;
                }
    
                your_textview.setTextSize(size);
                your_textview.invalidate();
    
            }
            else{
                //beyond limit, don't do anything
            }
        }
    

    Now in your onclick just call the method:

    public void onClick(View view) {
    
        switch(view.getId()) {
    
        case(R.id.txt_your_textview):
            increaseFontSize();
            break;
    
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two buttons and two divs(I put one above another). I made info
Let me first put the code snippets here. I am just using the ASP.NET
Sorry about the vague subject but I couldn't think what to put. Here's my
I find AWK really useful. Here is a one liner I put together to
I have two java classes. One is NewFrame.java where the forms(buttons, textfields) are located.
I have some jQuery code that highlights which radio button is checked by turning
Here is the way I can put float value to the stack(in C#): ILGenerator
Here's a snippet of a script of mine attempting to put extra Unicode awesomeness
My site is up here: Green McP I'm trying to put my old WP
I downloaded the swc file from here: http://developer.yahoo.com/maps/flash/flexGettingStarted.html And put it in my flex

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.