i want layout structure shown on picture. whatever tried, makes tabhost spreaded on linear, full screen.
this layout structure modified many times. tried weight , gravity , match_parent, fill parent.. of them make tabhost on top , bottom linear not visible. if see crazy tags, don't surprised :)
<?xml version="1.0" encoding="utf-8"?> <relativelayout android:layout_width="fill_parent" android:layout_weight="0" android:layout_height="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <tabhost android:id="@+id/tabhost" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_horizontal"> <tabwidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content"> </tabwidget> </tabhost> <linearlayout android:layout_weight="1" android:background="@color/white" android:layout_height="60dp" android:layout_marginstart="0dp" android:layout_margintop="0dp" android:layout_alignparentbottom="true" android:layout_width="fill_parent"> <button android:layout_width="100dp" android:layout_height="fill_parent" android:text="@string/finish_test" android:id="@+id/finishtest" android:background="@drawable/blueback" android:layout_alignparentright="true" android:layout_gravity="right" android:nestedscrollingenabled="false" android:onclick="onfinishclick" /> </linearlayout> </relativelayout>
but need screen divided 2 panels.
panel 1 - full area tabhost
panel 2 - fixed height , linear.
pls, help.
p.s. button hown part of lineat. pls, ignore it.
maybe it's important mention tab panels fill code. , each tab activity layout.
i way:
// on ecreate.. tabhost mtabhost = (tabhost) findviewbyid(r.id.tabhost); mtabhost.setup(getlocalactivitymanager()); try { mtabhost.addtab(mtabhost.newtabspec("tab0").setindicator("title1", null).setcontent(new intent(this, helloscreen.class))); mtabhost.addtab(mtabhost.newtabspec("tab1").setindicator("title2", null).setcontent(new intent(this, begintest.class))); mtabhost.addtab(mtabhost.newtabspec("tab2").setindicator("title3", null).setcontent(new intent(this, second.class))); } catch (exception e) { throw e; }
then hide tabwidget.. , these tabs (with activities inside) occupy full screen..
maybe wrong, me activity window in windows.. or in terms of winform.net - user control or winform..
in.net such structure works perfect.. i'm not sure how android manages activities..
the answer hidden in correct layout parameters , correct type of layouts.
you can use fragment or activity (they deprecated, found them easier implement, if need serve view (buttons, canvas, texts.. etc.).. everythin "the groove tube" when manage activity. adding tabs - use code above..
but layers.. should follows:
<?xml version="1.0" encoding="utf-8"?> <linearlayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"> <tabhost android:id="@+id/tabhost" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical"> <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" android:orientation="vertical"> <tabwidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content"> </tabwidget> </relativelayout> </tabhost> <linearlayout android:orientation="horizontal" android:layout_weight="1" android:background="@color/white" android:layout_height="60dp" android:layout_marginstart="0dp" android:layout_margintop="0dp" android:layout_alignparentbottom="true" android:layout_width="fill_parent"> <button android:layout_width="100dp" android:layout_height="fill_parent" android:text="@string/your_text" android:id="@+id/yourid" android:layout_alignparentright="true" android:layout_gravity="right" android:nestedscrollingenabled="false" android:onclick="onyourclick" /> </linearlayout> </linearlayout>
to hide tabhost tabwidget use:
mtabhost.gettabwidget().getchildat(0).setvisibility(view.gone);
on mainactivity ecreate..
and then.. use method.. button or code show required tab panel, using setcurrenttab(# of tab);
very smooth solution..
Comments
Post a Comment