Small Tabs appear using android.support.design.widget.TabLayout -
i'm trying create multiple tabs fragment each tab. have managed 2 tabs appear @ corner of layout. i'm unable divide width of tab layout equally tabs. code : activity_main.xml
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context=".mainactivity" android:id="@+id/mainlayout"> <android.support.design.widget.tablayout android:id="@+id/sliding_tabs" style = "mycustomtablayout" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabmode="scrollable" /> <android.support.v4.view.viewpager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="0px" android:layout_weight="1" android:background="@android:color/white" /> </linearlayout>
code : fragmentpageradapter
public class frag_adapter extends fragmentpageradapter { final int page_count =2; private string tabtitles[] = new string[] { "tab1", "tab2", "tab3" }; private context ccontext; public frag_adapter(fragmentmanager fm) { super(fm); } @override public int getcount() { return page_count; } @override public android.support.v4.app.fragment getitem(int i) { switch (i) { case 0: return new myfrag(); case 1: return new myfrag1(); default: return null; } } @override public charsequence getpagetitle(int position) { // generate title based on item position return tabtitles[position]; }
}
add app:tabgravity="fill"
tablayout xml if want distribute available space each tab.
change app:tabmode="scrollable"
in tablayout xml app:tabmode="fixed"
if want tabs shown.
Comments
Post a Comment