tabs - How can remove padding or margin in Tabwidget in android? -


i want create tabbed application. allright when create tab. space between tabs much. want remove padding or margin don't know how can that. suggestion?

xml

<?xml version="1.0" encoding="utf-8"?> <tabhost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"> <linearlayout     android:orientation="vertical"     android:layout_width="fill_parent"     android:layout_height="fill_parent">      <horizontalscrollview         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:fillviewport="true"         android:scrollbars="none" >     <tabwidget         android:id="@android:id/tabs"         android:padding="0px"         android:layout_margin="0px"          android:layout_width="wrap_content"         android:layout_height="wrap_content">          <textview             android:tag="tab0"             android:text="tab 1"             android:padding="0px"             android:layout_margin="0px"             android:layout_width="wrap_content"             android:layout_height="wrap_content"              />         <textview             android:tag="tab1"             android:text="tab 2"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             />         <textview             android:tag="tab2"             android:text="tab 3"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             />         <textview             android:tag="tab3"             android:text="tab 4"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             />         <textview             android:tag="tab4"             android:text="tab 5"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             />         <textview             android:tag="tab5"             android:text="tab 6"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             />         <textview             android:tag="tab6"             android:text="tab 7"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             />         <textview             android:tag="tab7"             android:text="tab 8"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             />         <textview             android:tag="tab8"             android:text="tab 9"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             />         <textview             android:tag="tab9"             android:text="tab 10"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             />      </tabwidget>     </horizontalscrollview>      <framelayout         android:id="@android:id/tabcontent"         android:layout_width="fill_parent"         android:layout_height="fill_parent">          <textview             android:text="hallo1"             android:layout_width="fill_parent"             android:layout_height="fill_parent" />         <textview             android:text="hallo2"             android:layout_width="fill_parent"             android:layout_height="fill_parent" />         <textview             android:text="hallo3"             android:layout_width="fill_parent"             android:layout_height="fill_parent" />         <textview             android:text="hallo4"             android:layout_width="fill_parent"             android:layout_height="fill_parent" />         <textview             android:text="hallo5"             android:layout_width="fill_parent"             android:layout_height="fill_parent" />         <textview             android:text="hallo6"             android:layout_width="fill_parent"             android:layout_height="fill_parent" />         <textview             android:text="hallo7"             android:layout_width="fill_parent"             android:layout_height="fill_parent" />         <textview             android:text="hallo8"             android:layout_width="fill_parent"             android:layout_height="fill_parent" />         <textview             android:text="hallo9"             android:layout_width="fill_parent"             android:layout_height="fill_parent" />         <textview             android:text="hallo10"             android:layout_width="fill_parent"             android:layout_height="fill_parent" />      </framelayout>    </linearlayout> </tabhost> 

here code:

public class mainactivity extends activity {  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      setcontentview(r.layout.activity_main);      tabhost tabhost = (tabhost) findviewbyid(android.r.id.tabhost);     tabhost.setup();      final tabwidget tabwidget = tabhost.gettabwidget();     final framelayout tabcontent = tabhost.gettabcontentview();     tabhost.gettabwidget().setdividerdrawable(r.drawable.empty);      // original tab textviews , remove them viewgroup.     textview[] originaltextviews = new textview[tabwidget.gettabcount()];     (int index = 0; index < tabwidget.gettabcount(); index++) {         originaltextviews[index] = (textview) tabwidget.getchildtabviewat(index);     }     tabwidget.removeallviews();      // ensure tab content childs not visible @ startup.     (int index = 0; index < tabcontent.getchildcount(); index++) {         tabcontent.getchildat(index).setvisibility(view.gone);     }      // create tabspec based on textview childs in xml file.     // or create simple tabspec instances in other way...     (int index = 0; index < originaltextviews.length; index++) {         final textview tabwidgettextview = originaltextviews[index];         final view tabcontentview = tabcontent.getchildat(index);          tabspec tabspec = tabhost.newtabspec((string) tabwidgettextview.gettag());         tabspec.setcontent(new tabhost.tabcontentfactory() {             @override             public view createtabcontent(string tag) {                 return tabcontentview;             }         });         if (tabwidgettextview.getbackground() == null) {             tabspec.setindicator(tabwidgettextview.gettext());         } else {             tabspec.setindicator(tabwidgettextview.gettext(), tabwidgettextview.getbackground());         }         tabhost.addtab(tabspec);     }       tabhost.gettabwidget().setdividerdrawable(r.drawable.empty);      if (integer.parseint(build.version.sdk) >= build.version_codes.honeycomb) {         tabhost.gettabwidget().setshowdividers(linearlayout.show_divider_none);     }  //      tabhost.setcurrenttab(0);     } } 

enter image description here

if @ base style of tablayout:

<style name="base.widget.design.tablayout" parent="android:widget">     <item name="tabmaxwidth">@dimen/tab_max_width</item>     <item name="tabindicatorcolor">?attr/coloraccent</item>     <item name="tabindicatorheight">2dp</item>     <item name="tabpaddingstart">12dp</item>     <item name="tabpaddingend">12dp</item>     <item name="tabbackground">?attr/selectableitembackground</item>     <item name="tabtextappearance">@style/textappearance.design.tab</item>     <item name="tabselectedtextcolor">?android:textcolorprimary</item> </style> 

you van see these 2 lines

    <item name="tabpaddingstart">12dp</item>     <item name="tabpaddingend">12dp</item> 

so create style tablayout this:

  <style name="tab_bar">         <item name="android:layout_width">match_parent</item>         <item name="android:layout_height">65dp</item>         <item name="android:background">@color/backgroundcolor</item>         <item name="android:tabstripenabled">false</item>         <item name="tabpaddingstart">0dp</item>         <item name="tabpaddingend">0dp</item>     </style> 

and use style:

<android.support.design.widget.tablayout android:id="@+id/tabs"             app:tabgravity="fill"             app:tabmode="fixed"             style="@style/tab_bar"/> 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -