vivek
vivek

Reputation: 45

Basic design needed

i am targeting an app on android 2.1. i am having a layout which contains three sections. the header, mainbody and the footer. the footer remains same all through the application lifecycle. the footer has four options for the user to select(like four tabs). when the user selects each option in the footer the content has to change in the mainbody. and when the user interacts with the UI in the mainbody, there is a need to change the content of just the mainbody(like activity replacing an activity). and the user selection in the footer has to remain highlighted untill user selects another option in the footer.i alomost have a need like, launching activities within the same tab, but the tabs are placed below. a lot of people have suggested using activitygroup but as it is deprecated how do i go about doing this?. if anybody needs more clarity about question i am ready to provide

Upvotes: 0

Views: 132

Answers (3)

Alex A.
Alex A.

Reputation: 2736

Another possible approach is using fragments instead of a full activity per content page. Fragments are a lot like activities, except that they need to be embedded in an activity to be displayed and they give you the freedom to change the content of one part of an activity (that is, swapping one fragment for another), meaning you can have another part of the activity remain unchanged - for instance tabs for switching between these fragments. A nice bonus is that reusing that content page in another activity is very easy, and should you choose create a tablet-friendly version you can easily compose more complex views of your existing fragments.

Using a ViewPager together with some type of page indicator, such as the tab indicator here you can have an active fragment and easily switch between them.

Since you are targeting 2.1 you will need to use the android support library to support fragments.

Upvotes: 0

Andy Res
Andy Res

Reputation: 16043

To display the footer menu across all activities, you may create a custom layout - the layout of the footer - and include it in every activity, or to be more specific, include it in the layout of every activity with <include />

Also, all your activities should have a parent activity, let it be BaseActivity, where you will provide appropriate actions for you footer menu.

Then you will need just to inherit the BaseActivity and include the footer menu layout, into your current layout, to have the menu available for any Activity you would like.

Upvotes: 0

Dmytro Zarezenko
Dmytro Zarezenko

Reputation: 10686

If you want support from lower versions like 2.1 and higher I can propose my way. I always use separate XML layout for tray (footer in your case), for example (res/layout/tray.xml):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainMenu"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom"
    android:background="#EEEEEE"
    android:gravity="bottom|fill_horizontal"
    android:orientation="horizontal"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/addBtn"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/add" android:layout_weight="0.2"/>

    <ImageView
        android:id="@+id/catalogBtn"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/catalog" android:layout_weight="0.2"/>

    <ImageView
        android:id="@+id/searchBtn"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/search" android:layout_weight="0.2"/>

    <ImageView
        android:id="@+id/settingsBtn"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/settings" android:layout_weight="0.2"/>

    <ImageView
        android:id="@+id/infoBtn"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:src="@drawable/info" android:layout_weight="0.2"/>

</LinearLayout>

And includes it in every Activity I need:

<include layout="@layout/tray" android:id="@+id/tray" />

After that I can in java code hide/show some buttons in tray by ID, or select some of them with another color ...

Upvotes: 1

Related Questions