Why The Tab Widget Is Above The Content In Android?
Currently I work on a tabhost layout. In most android app the layout is: tab1 | tab 2 ____________ Tab 1 content (if I press on tab1) However, what I would like to achieve is Ta
Solution 1:
you can add tabwidget to the bottom using the given code..
<?xml version="1.0" encoding="utf-8"?><TabHostxmlns:android="http://schemas.android.com/apk/res/android"android:id="@android:id/tabhost"android:layout_width="match_parent"android:layout_height="match_parent" ><RelativeLayoutandroid:layout_width="match_parent"android:layout_height="match_parent" ><FrameLayoutandroid:id="@android:id/tabcontent"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_above="@android:id/tabs" /><TabWidgetandroid:id="@android:id/tabs"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_alignParentBottom="true" /></RelativeLayout></TabHost>
Solution 2:
Found out the solution using the support fragment tab host:
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><FrameLayoutandroid:id="@+id/realtabcontent"android:layout_width="match_parent"android:layout_height="0dip"android:layout_weight="1" /><android.support.v4.app.FragmentTabHostandroid:id="@android:id/tabhost"android:layout_width="match_parent"android:layout_height="wrap_content" ><TabWidgetandroid:id="@android:id/tabs"android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="horizontal" /></android.support.v4.app.FragmentTabHost></LinearLayout>
Solution 3:
Try this way,hope this will help you to solve your problem.
activity_main.xml
<android.support.v4.app.FragmentTabHostxmlns:android="http://schemas.android.com/apk/res/android"android:id="@android:id/tabhost"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><FrameLayoutandroid:id="@android:id/tabcontent"android:layout_width="0dp"android:layout_height="0dp"android:layout_weight="0"/><FrameLayoutandroid:id="@+id/realtabcontent"android:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"/><TabWidgetandroid:id="@android:id/tabs"android:orientation="horizontal"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_weight="0"/></LinearLayout></android.support.v4.app.FragmentTabHost>
tab1_view.xml
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#31152C"android:gravity="center"><ScrollViewandroid:layout_width="match_parent"android:layout_height="wrap_content" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"android:gravity="center"><ImageViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:adjustViewBounds="true"android:src="@drawable/ic_launcher" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:textSize="20sp"android:text="Home"/></LinearLayout></ScrollView></LinearLayout>
tab2_view.xml
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#31152C"android:gravity="center"><ScrollViewandroid:layout_width="match_parent"android:layout_height="wrap_content" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"android:gravity="center"><ImageViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:adjustViewBounds="true"android:src="@drawable/ic_launcher" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:textSize="20sp"android:text="Car Park"/></LinearLayout></ScrollView></LinearLayout>
tab3_view.xml
<LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#31152C"android:gravity="center"><ScrollViewandroid:layout_width="match_parent"android:layout_height="wrap_content" ><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical"android:gravity="center"><ImageViewandroid:layout_width="match_parent"android:layout_height="wrap_content"android:adjustViewBounds="true"android:src="@drawable/ic_launcher" /><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:textSize="20sp"android:text="Shop"/></LinearLayout></ScrollView></LinearLayout>
MainActivity.java
publicclassMainActivityextendsFragmentActivity{
private FragmentTabHost mTabHost;
@Overrideprotected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
mTabHost.addTab(mTabHost.newTabSpec("tab1").setIndicator("Tab 1",getResources().getDrawable(R.drawable.ic_launcher)),
Home.class, null);
mTabHost.addTab(mTabHost.newTabSpec("tab2").setIndicator("Tab 2",getResources().getDrawable(R.drawable.ic_launcher)),
CarPark.class, null);
mTabHost.addTab(mTabHost.newTabSpec("tab3").setIndicator("Tab 3", getResources().getDrawable(R.drawable.ic_launcher)),
Shop.class, null);
}
}
Home.java
publicclassHomeextendsFragment{
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
ViewV= inflater.inflate(R.layout.tab1_view, container, false);
return V;
}
}
CarPark.java
publicclassCarParkextendsFragment {
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
ViewV= inflater.inflate(R.layout.tab2_view, container, false);
return V;
}
}
Shop.java
publicclassShopextendsFragment {
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
ViewV= inflater.inflate(R.layout.tab3_view, container, false);
return V;
}
}
Post a Comment for "Why The Tab Widget Is Above The Content In Android?"