How to set the size of images and fonts in tabwidget in Android

Source: Internet
Author: User

Because the image resources in the project are all renewed from the Internet, the figure in tabwidget is too large to overwrite the text. The initial effect is as follows:

Most of the search results on the Internet are about how to change the font size and color. The code below sets the font color and size of tabs in tabhost;
Tabwidget = This. gettabwidget ();
For (INT I = 0; I <tabwidget. getchildcount (); I ++ ){
Textview TV = (textview) tabwidget. getchildat (I). findviewbyid (Android. R. Id. Title );
TV. setgravity (bind_auto_create );
TV. setpadding (10, 10, 10, 10 );
TV. settextsize (16); // set the font size;
TV. settextcolor (color. White); // you can specify the font color;
// Obtain the tabs image;
Imageview IV = (imageview) tabwidget. getchildat (I). findviewbyid (Android. R. Id. Icon );
} Based on the above example, we estimate that two methods will be used to solve the problem 1. For (INT I = 0; I <tabwidget. getchildcount (); I ++ ){

// Obtain the tabs image;
Imageview IV = (imageview) tabwidget. getchildat (I). findviewbyid (Android. R. Id. Icon );
Iv. setmaxheight (30 );
Iv. setmaxwidth (30 );
} So we can find that there is still no effect 2. For (INT I = 0; I <tabwidget. getchildcount (); I ++ ){

// Obtain the tabs image;
Imageview IV = (imageview) tabwidget. getchildat (I). findviewbyid (Android. R. Id. Icon );
Iv. setlayoutparams (New layoutparams (width, height ));
}
But in this case, the program will go wrong. Why? Because layoutparams (width, height) of the parent control must be used in new layoutparams, while we did not find any suitable organization import when importing the package, all the results found that no matter which one will go wrong, 3. Therefore, we must seek another method for (INT I = 0; I <tabs. getchildcount (); I ++)
{
Textview = (textview) tabs. getchildat (I). findviewbyid (Android. R. Id. Title );
Textview. settextsize (14 );
Textview. setpadding (0, 3, 0, 0 );
Imageview image = (imageview) tabs. getchildat (I). findviewbyid (Android. R. Id. Icon );

Image. getlayoutparams (). Height = 30; // you can solve the problem by assigning values to its attributes.
Image. getlayoutparams (). width = 30;
} The result is the initial goal.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.