[Android] three methods to set tabhost to the bottom

Source: Internet
Author: User

The tabhost component that comes with Android is located at the top of the page. If you want it to be located at the bottom of the page, two methods are provided here.

Method 1

1. tabcontent and tabs interchange locations

2. Set the attributes of tabcontent: android: layout_weight = "1"

Example
<? Xml version = "1.0" encoding = "UTF-8"?> <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "match_parent" android: layout_height = "match_parent"> <TabHost android: id = "@ android: id/tabhost" android: layout_width = "match_parent" android: layout_height = "match_parent" android: layout_alignParentLeft = "true" android: Layout = "true"> <LinearLayout android: layout_width = "match_parent" android: layout_height = "match_parent" android: orientation = "vertical"> <FrameLayout android: id = "@ android: id/tabcontent" android: layout_width = "match_parent" android: layout_height = "match_parent" android: layout_weight = "1"> the middle part is omitted </FrameLayout> <TabWidget android: id = "@ android: id/tabs" android: layout_width = "match_parent" android: layout_height = "wrap_content"> </TabWidget> </LinearLayout> </TabHost> </RelativeLayout>


Method 2

1. tabcontent and tabs interchange locations

2. put tabs in a relativeLayout, and add the following attributes: android: layout_alignParentBottom = "true"

Example
<? Xml version = "1.0" encoding = "UTF-8"?> <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "match_parent" android: layout_height = "match_parent"> <TabHost android: id = "@ android: id/tabhost" android: layout_width = "match_parent" android: layout_height = "match_parent" android: layout_alignParentLeft = "true" android: Rule = "true"> <FrameLayout android: id = "@ android: id/tabcontent "android: layout_width =" match_parent "android: layout_height =" match_parent "> omitted middle part </FrameLayout> <RelativeLayout android: layout_width =" match_parent "android: layout_height = "match_parent"> <TabWidget android: id = "@ android: id/tabs" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: layout_alignParentBottom = "true"> </TabWidget> </RelativeLayout> </TabHost> </RelativeLayout>

Method 3 1. Change the positions of tabcontent and tabs (tabs is moved below the LinearLayout label). 2. Add the attribute to tabcontent: android: layout_gravity = "top"
3. Add attributes to tabs: android: layout_gravity = "bottom"
Example
<? Xml version = "1.0" encoding = "UTF-8"?> <RelativeLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "fill_parent" android: layout_height = "fill_parent"> <TabHost android: id = "@ android: id/tabhost" android: layout_width = "match_parent" android: layout_height = "match_parent" android: feature = "true" android: layout_alignParentLeft = "true"> <LinearLayout android: layout_width = "match_parent" android: layout_height = "match_parent" android: orientation = "vertical"> <FrameLayout android: id = "@ android: id/tabcontent" android: layout_width = "match_parent" android: layout_height = "match_parent" android: layout_gravity = "top"> the middle part is omitted </FrameLayout> </LinearLayout> <TabWidgetandroid: id = "@ android: id/tabs" android: layout_width = "match_parent" android: layout_height = "wrap_content" android: layout_gravity = "bottom"> </TabWidget> </TabHost> </RelativeLayout>



Related Article

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.