Android learning notes (5): Android tabwidget height text center adjustment

Source: Internet
Author: User

Today, I mainly studied Android tabwidget, but at first I was not satisfied with the adjustment of height and text center.

If the image display effect is not added, it may not feel good.


It feels so bad. Then process the tabwidget.

The process is as follows:

Tabwidget = tabhost. gettabwidget (); For (INT I = 0; I <tabwidget. getchildcount (); I ++) {view child = tabwidget. getchildat (I); Final textview TV = (textview) child. findviewbyid (Android. r. id. title); relativelayout. layoutparams Params = (relativelayout. layoutparams) TV. getlayoutparams (); Params. addrule (relativelayout. align_parent_bottom, 0); // cancel text baseline align_parent_bottom. addrule (relativelayout. center_in_parent, relativelayout. true); // set the center alignment of the text}


However, this is highly uncoordinated, and you need to adjust the height and then change the code.

Tabwidget = tabhost. gettabwidget (); For (INT I = 0; I <tabwidget. getchildcount (); I ++) {view child = tabwidget. getchildat (I); Final textview TV = (textview) child. findviewbyid (Android. r. id. title); relativelayout. layoutparams Params = (relativelayout. layoutparams) TV. getlayoutparams (); Params. addrule (relativelayout. align_parent_bottom, 0); // cancel text baseline align_parent_bottom. addrule (relativelayout. center_in_parent, relativelayout. true); // set the text center to align with child. getlayoutparams (). height = 30; // final imageview IV = (imageview) Child //. findviewbyid (Android. r. id. icon); // IV. getlayoutparams (). height = 0 ;}


View the display result again



In the end, we can achieve what we want!


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.