Action bar below a tab view
I want to create a TabView like in this example: http://developer.android.com/resources/tutorials/views/hello-tabwidget.html
Below it I'd like an action bar with buttons that should always appear on the bottom of the screen. How ever. When i place another LinearLayout with vertical orientation to the TabHost it disappears beyond the screen limits. Here is my 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"
android:padding="5dp">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content" />
<FrameLayout android:id="@android:id/tabcon开发者_开发问答tent"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp" />
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:baselineAligned="false">
<Button android:text="Add" android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<ToggleButton android:text="Aus" android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</LinearLayout>
</LinearLayout>
</TabHost>
Is there a way to do this dynamically?
Edit: Added my xml code
In that layout definition, something's gotta give. Currently, both the FrameLayout
for the tab contents and the LinearLayout
below it are asking to fill the remaining height of the screen with `android:layout_height="fill_parent".
In order to do what you are expecting, you need to define the "action bar" LinearLayout
to wrap its contents vertically, and tell the FrameLayout
simply to fill the available space between the tabs and that bottom bar. We do this by adding a weight parameter. I've modified your inner layout below with these two things:
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:padding="5dp" />
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:baselineAligned="false">
<Button android:text="Add"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
<ToggleButton android:text="Aus"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
</LinearLayout>
</LinearLayout>
Hope that Helps!
You probably need to surround your 'action bar' and other linear layout inside another linear layout.
So you tab has a linear layout for it's content. In that linear layout you have linear layout for the real content. Then you have your action bar.
Psuedo code:
<LinearLayout...>
<LinearLayout...>
<!-- Views here for the content of the tab -->
</LinearLayout>
<MyActionBarView...>
</MyActionBarView>
</LinearLayout>
I found the answer by searching for the keyword bottom in within the android-layout tag. The answer is Relative Layout. Here is the functioning 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">
<RelativeLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget android:id="@android:id/tabs"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<RelativeLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/relativeLayout1"
android:layout_alignParentBottom="true">
<Button android:text="Add" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_alignParentLeft="true" />
<ToggleButton android:text="Aus" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_alignParentRight="true" />
</RelativeLayout>
<FrameLayout android:layout_width="fill_parent"
android:id="@android:id/tabcontent" android:layout_height="wrap_content"
android:padding="5dp" android:layout_below="@android:id/tabs"
android:layout_alignParentLeft="true"></FrameLayout>
</RelativeLayout>
</TabHost>
精彩评论