0

I wanted to have a "info bar/textview" right below my App's action bar (the bar that says the title, app picture, etc).

I have tabs on my application, and I wanted the infobar ABOVE the tabs, right below the action bar. I know how to change the main' layout xml to put it below the tabs using a layout, but I can't figure out if it's possible to place the bar above the tabs. I can't put it above the tabs because I think they're 'part' of the action bar.

4

1 回答 1

1

为信息栏和选项卡创建 xml 布局。例如:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/infobar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Info Bar" />

    <RelativeLayout
        android:id="@id/tab_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_below="@+id/infobar" >
    </RelativeLayout>

</RelativeLayout>

用您自己的布局替换信息栏文本视图。注意相对布局“tab_layout”?那将是选项卡将占用的空间。按照这里的例子。取自链接上的示例:

/* The following are each of the ActionBar.TabListener callbacks */

    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // Check if the fragment is already initialized
        if (mFragment == null) {
            // If not, instantiate and add it to the activity
            mFragment = Fragment.instantiate(mActivity, mClass.getName());
            ft.add(android.R.id.content, mFragment, mTag);
        } else {
            // If it exists, simply attach it in order to show it
            ft.attach(mFragment);
        }
    }

改变这个:ft.add(android.R.id.content, mFragment, mTag)到这个 ft.add(R.id.tab_layout, mFragment, mTag)。请注意,我们使用了自己的布局而不是 android.R.id.content。

于 2013-04-30T04:27:08.570 回答