w4beda
w4beda

Reputation: 67

Framelayout in Fragment Tab

I'm trying to get a frame layout in my app. I have two tabs, each tab is a fragment. In one tab (listview) I want that two Seekbars appear when a button on the action bar is pressed.I know that I have to use Framelayout but not how to apply it? Please give me some hints how to get this done Thanks

Upvotes: 3

Views: 1043

Answers (1)

Geek_Soledad
Geek_Soledad

Reputation: 26

I think may be you can reference my sample follow ,it use android.support.v4 library. At first, write a layout file for your activity like this :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<android.support.v4.app.FragmentTabHost
    android:id="@+id/frag_tabhost"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<LinearLayout
    android:id="@+id/content_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</LinearLayout>

then in your MainActivity code, you can do like this :

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.activity_main);
        initializeTabHost();
    }

    /**
     * 初始化TabHost
     */
    private void initializeTabHost() {
        tabHost.setup(this, getSupportFragmentManager(), R.id.content_layout);
        TabSpec tabSound = tabHost.newTabSpec(TAB_SOUND).setIndicator(
                getString(R.string.settings_sound));
        TabSpec tabAdvanced = tabHost.newTabSpec(TAB_ADVANCED).setIndicator(
                getString(R.string.settings_advanced));
        TabSpec tabLocal = tabHost.newTabSpec(TAB_LOCAL).setIndicator(
                getString(R.string.settings_local));
        tabHost.addTab(tabSound, SoundFragment.class, null);
        tabHost.addTab(tabAdvanced, AdvancedFragment.class, null);
        tabHost.addTab(tabLocal, LocalFragment.class, null);
    }

and make this class extends FragmentActivity. then write a class extends Fragment, override the onCreateView method :

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_list, container, false);
    return view;
}

Hope it can help you.

Upvotes: 1

Related Questions