Siddharth Lele
Siddharth Lele

Reputation: 27748

Fixed action bar similar to the Facebook app

I have implemented the action bar (not the quick action bar) in my app. The action bar is based on the one used in the Google IO app and the Facebook app. I am stumped though, trying to understand how to keep the action bar fixed. When an activity needs scrolling, the action bar needs to be remain fixed. Can anyone help with this problem?

Upvotes: 1

Views: 2622

Answers (2)

Yoni Samlan
Yoni Samlan

Reputation: 38065

Some good stuff in Jon's post, but if you're just looking for the simple answer to work with your existing layouts/activities, just use a vertical LinearLayout with the first child as the titlebar and the second as the ScrollView, setting the ScrollView height to fill_parent (or setting fillViewport to true). Alternatively, use a RelativeLayout with the scrollview set to layout below the title, or with a top margin on the scrollview equal to the height of the title bar.

Upvotes: 2

Jon Willis
Jon Willis

Reputation: 7024

I'm developing an open-source app that is adapted from Google IO. I made a generic version of the titlebar that they used - called CustomTitlebarActivity which subclasses Activity.

As an example, I'll refer you to my HomeActivity implementation which subclasses CustomTitlebarActivity; since I abstract the titlebar away from the activity's layout, you can easily add a ScrollView below it that will not scroll the titlebar out of view.

An added benefit to this design choice is a lot more code re-use than Google IO had, with some ..quirks that are easily circumvented. I won't go into that in more detail here though.

HomeActivity

res:

http://code.google.com/p/electricsleep/source/browse/beta/res/layout/activity_home.xml

src:

http://code.google.com/p/electricsleep/source/browse/beta/src/com/androsz/electricsleepbeta/app/HomeActivity.java

CustomTitlebarActivity

res:

http://code.google.com/p/electricsleep/source/browse/beta/res/layout/titlebar.xml

src:

http://code.google.com/p/electricsleep/source/browse/beta/src/com/androsz/electricsleepbeta/app/CustomTitlebarActivity.java

Also, I have one activity that has a scrollview inside it, (though it is inside a ViewFlipper) in case you have trouble. Check out the res:

http://code.google.com/p/electricsleep/source/browse/beta/res/layout/wizard_welcome.xml

Upvotes: 1

Related Questions