Как добавить панель действий над TabWidget?

#java #android #android-layout #android-relativelayout #android-actionbar

#java #Android #android-макет #android-relativelayout #android-панель действий

Вопрос:

Я создаю пользовательскую панель над TabHost. По какой-то причине пользовательская панель не отображается над TabHost, вместо этого она нарисована за ним. Не уверен, почему. Вот мой 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:layout_height="wrap_content" android:layout_width="match_parent" android:id="@ id/actionbarRelativeLayout">
        <ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/icon" android:id="@ id/stocktwitsImageButton"></ImageButton>
        <ImageButton android:layout_height="wrap_content" android:layout_width="wrap_content" android:src="@drawable/icon" android:id="@ id/composeImageButton" android:layout_alignParentRight="true"></ImageButton>
    </RelativeLayout>
-->

    <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:padding="5dp" />
    </LinearLayout>
</TabHost>
  

Комментарии:

1. TabHost не отображает на экране никаких компонентов, это делается TabWidget.

2. отредактированный вопрос, чтобы быть более точным. как я могу поместить что-то над TabWidget?

Ответ №1:

Не используйте TabHost в качестве корня вашего макета. Поместите свой TabHost внутрь LinearLayout с orientation:vertical помощью.

Затем внутри LinearLayout и перед TabHost вы можете поместить свою панель действий.

Комментарии:

1. Чтобы отобразить XML, мне нужно знать: когда вы говорите о ActionBar, вы имеете в виду панель действий в Honeycomb или просто шаблон? В приложении Google IO, разработанном до Honeycomb ( code.google.com/p/iosched/source/browse/trunk/res/layout / … ) содержит пример того, как использовать LinearLayout и самодельную панель действий.

2. я делаю самодельную панель действий. Посмотрите на мой относительный макет, который закомментирован.

3. @Sheehan Помог ли вам приведенный выше пример приложения Google IO в дальнейшем?