android layout with fixed top and bottombar - android

I'm trying to build an application with a fixed top and bottombar (bars should host other controls like buttons, progressbar,...).
The content (space between top/bottombar) should be able to host activities and navigates to other activies, which also could be resulting in also changing the content of both bars (also load other activities for bars).
I've started a sample with actionBar, had this issue with fullscreen mode (Is there a theme for Holo, full screen but with Action Bar?). Resolves my problem but setting it in code behind isn't a recommended way.
What do you think? Is there a better way to reach this kind of layout, maybe is it better to use a more simple control then actionbar?
If yes, it would be great if someone knows a starting point for layouting this (example, tut) and how to realize the navigation for the content.
I'm coming from wpf with regions, I also read posts about similar functionality on stackoverflow, but I only found examples where I missed the functionality of a dynamic content (for the bars and the content between the bars).
Tons of thanks for replies

This should work (Replace middle button with say a scrollview) :
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/topbutton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentTop="true" >
</Button>
<Button
android:id="#+id/bottombutton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true" >
</Button>
<Button
android:id="#+id/middlebutton"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_above="#id/bottombutton"
android:layout_below="#id/topbutton" >
</Button>
</RelativeLayout>
Reason why the bottom button has to be above the middle button in XML's order is that a view can only refer(e.g. android:layout_above) to views above itself.

Related

Android : SlidingDrawer & wrong display

I have to use SlidingDrawer in my app. I know this class is deprecated but it very useful to do what i want so i have decided to use it.
I've used this link
Android: can height of SlidingDrawer be set with wrap_content?
in order to use wrap_content when the SlidinDrawer is open. It works perfect on android 4.2.2 with AOSP rom but with android 4.0.4 on SGSII (Samsung rom), i have some display problem when i open or close the SlidingDrawer. If there is no action, the widget appears correctly.
Have you any idea why there is this problem ?
Edit : Here is a screenshot. The problem disappeared when i took a screenshot, so to see the problem i took a photo with another device.
Alternate to SlidingDrawer is "Custom Sliding Drawer".
Sephiroth has created one of it. It has option to sliding up and down. It has handler which is used like actual handle to open and close Sliding Drawer.
I will suggest you to implement this custom one. This will solve your problem.
You just need to define following in your layout
<view class="it.sephiroth.demo.slider.widget.MultiDirectionSlidingDrawer"
xmlns:my="http://schemas.android.com/apk/res/it.sephiroth.demo.slider"
android:id="#+id/drawer"
my:direction="topToBottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
my:handle="#+id/handle"
my:content="#+id/content">
<include android:id="#id/content"
layout="#layout/pen_content" />
<imageview android:id="#id/handle"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:src="#drawable/sliding_drawer_handle_bottom" />
</view>
Thats it. Your sliding drawer is ready to work.

Sherlock Actionbar custom design

I will be very thankfull if anyone will help me find out some details about customizing sherlock actionbar.
To be more concrete: I need an action bar with four buttons. Two small buttons on the sides of the bar (on on the left side and second on the right), and one "paired" radiobutton in the middle of the bar.
When I say "paired" I mean something like in iOS when there are two buttons positioned near each other and when I press one - the second is unpressed and vice versa.
All in all it should look like this.
Is it even possible to make this or I should forget about using the wonderful sherlock creature?
I would personally abandon the idea of using ActionBarSherlock and instead just implement this using your own layout resource.
As a user of ActionBarSherlock I can say it's a fantastic library, as it essentially allows you to use the ActionBar API across all devices, including pre-Honeycomb, meaning you don't have to code a separate UI to suit pre-Honeycomb device. But the point of ActionBarSherlock is that it just provides APIs that are equivalent to those of the native ActionBar. And the problem is that the ActionBar is restrictive in what you can creatively do with it, because it is designed to offer specific functionality and controls that kind of fit around how Google want you to implement your UI. In a nutshell, you can specify a custom layout View that appears somewhere within the bar. You can also control which menu items appear as action items placed on the right-hand side of the bar (though it is ultimately still up to the system, based on screen space, if such items are made visible on the bar). The bar also allows you to implement some very special functionality (Action Views, Action Providers, etc.)
But if you're looking to create a very customised layout like the one you've pictured, and you don't need the special functionality that the ActionBar (or ActionBarSherlock) provides, then you might be better off doing it from scratch.
Yes you can make your Sherlock ActionBar like you show above. you have to set custom View to your SherLock ActionBAr. Just few lines of code
getSupportActionBar()
.setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(
R.layout.your_custom_layout);
and you custom layout should be RelativeLayout something like this
<?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="72dp" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#drawable/icon" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/icon" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:src="#drawable/icon" />
</LinearLayout>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="#drawable/icon" />
</RelativeLayout>

Android 4.0 Tabbed Activity Layout

I have 2-3 Activities in my app that all share data in a memory pool. I want to be able to easily switch between these activities while keeping them all simultaneously running. In addition, I am developing for Android 4.0. I would like to use TabActivity, but it has been deprecated and replaced with ActionBar, which I have tried but I don't think it's what I'm looking for. I want large tabs, similar to the classic "Artist/Playlist/All" tabs found in the stock Android Music Application, or like the Tab Bar seen at the bottom of the screenshot below. Does anyone know of a library to create these tabs or a way to make ActionBar more customizable? Or is using TabActivity a perfectly good solution, even on ICS devices?
ActionBar is what you're looking for, actually.
You should convert your Activites to Fragments. Assuming they're not too complex, this shouldn't be hard at all. There are tons of examples out there. You need one Activity, preferably a FragmentActivity, to hold all of them.
This should help:
http://arvid-g.de/12/android-4-actionbar-with-tabs-example
There are several subquestions to this, I'll try to address them all:
-In order to use the top tabs, you want to use an ActionBar.
-If you were to do it in the style of the music app, where you swipe sideways between views and the label of the current one is always front and center... For that, the class you'd want to use is called ViewPager
You can see all of these methods by creating a new Activity in eclipse, and going through the wizard. Under "Navigation Type" you can select "Tabs", "Tabs + Swipe", "Swipe Views + Title Strip". Create any one of those Activities to see how it looks, and then look at the code to see how it's implemented & how to customize it.
-Navigation along the bottom is discouraged- See the Android Design Guide, spec the section "Don't use Bottom Tab Bars"
You have probably found an answer by now, but I thought I'll share another way you could create something like that tab bar using images and xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="#+id/main">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/tabackground"
android:layout_alignParentBottom="true"
android:id="#+id/llBottom">
<ImageButton
android:src="#drawable/icon2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
/>
<ImageButton
android:src="#drawable/icon3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
/>
<ImageButton
android:src="#drawable/icon4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
/>
<ImageButton
android:src="#drawable/icon5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#00000000"
/>
</LinearLayout>
<ImageView
android:layout_height="24dp"
android:layout_width="fill_parent"
android:layout_alignTop="#+id/llBottom"
android:background="#10ffffff"/>
<ImageView
android:layout_height="1dp"
android:layout_width="fill_parent"
android:layout_alignTop="#+id/llBottom"
android:background="#30ffffff"/>
</RelativeLayout>
Is not perfect but with some creativity and changing some values it can look very good.
Hope it helps in some way.

Android GUI: what are the good UI patterns for entering an integer number?

There are two numbers constantly displayed in my UI. I need the user to be able to specify those numbers. In a desktop app I simply use 2 spinbuttons, and can beat it (I guess). However, there are problems with this in Android (I am targeting Android 3-based tablets).
First of all, I've tried NumberPicker widget, but it simply does not show itself properly (I've asked a question about it, but no response so far).
Then I've tried some 3rd-party numberpicker implementations one cand find on the Web, but for various reason didn't like neither of them. Some of them are too large to fit the side panel I'm squeezing controls into, some are just ugly (and too small, probably), and all of them automatically grab input focus causing the keyboard to show every time I open this side panel.
There is another option - only show the uneditable label with a number on the panel, and show popup window with some numberpickers in it. Apart from me not knowing how to implement such a popup (just learning), how do I decorate the label so that the user understands he can tap it to edit?
Perhaps, there are better solutions for this problem? I took a look at some apps from Google Market, and they all seem to either use huge NumberPickers at the center of the screen (and I need as much of the screen as possible clear), or a popup with the same huge Numberpickers I don't particularly like.
Can you suggest anything else? Thanks in advance!
There are two different issues in your question:
For the number picker for eaxmple in my case I have created a simple tool. You can just put a button with the text "-" then a textview and then a button with "+". You put it in a linear layout and t can be vertical or horizontal. If you want it you can make it very small. For example here is what I have wrote but you can try playing with the options to see which is better for you.
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:orientation="vertical" android:id="#+id/linearLayout1"
android:layout_width="wrap_content" android:layout_weight="1"
android:layout_height="wrap_content">
<Button android:id="#+id/button22" android:layout_gravity="center"
android:layout_weight="1" android:text="+" android:gravity="center"
android:layout_width="30dip" android:layout_height="30dip"></Button>
<Button android:id="#+id/button11"
android:layout_gravity="center"
android:layout_weight="1" android:text="-"
android:gravity="center" android:textAppearance="?android:attr/textAppearanceSmall" android:layout_height="30dip" android:layout_width="30dip"></Button>
</LinearLayout>
<LinearLayout android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="1" android:orientation="vertical">
<Button android:layout_weight="1"
android:layout_height="fill_parent"
android:layout_width="30dip"
android:text="0" android:id="#+id/quantidad"></Button>
</LinearLayout>
then you can add onClick listeners on the buttons and setup to increase or decrase the text displayed in the text view.
As for the keyboard well if you use that example you not need it but if you use an edittext then you can setup an option for the keyboard to be hidden in the manifest: you can see the option here http://developer.android.com/guide/topics/manifest/activity-element.html

Is there a view for a button bar? (Image link describing the view)

I am looking for a view or some sort of information regarding the bottom bar in default applications of Android such as Email, or Unlock pattern as shown in the picture below. I have not been able find anything about this on Androids site nor from Google searches.
Image: http://img11.imageshack.us/i/viewdn.jpg/
I believe that Christopher is correct; there is no special widget to create the bar in your image. However, if you want to emulate it, you can create a layout and use the style style="#android:style/ButtonBar". That will give you the light gray background and the correct margins.
I don't believe there's any standard view for the button bar used at the bottom of these apps; it's generally just two Button items placed together in a LinearLayout or RelativeLayout.
For example, looking at the Android Open Source Project, you can see the button bar for one of the email app setup screens is defined as two plain old Button objects.
However, it is surprising that Google didn't abstract more of the common stuff into an Android theme or sublayout, rather than having the same views and attributes in each layout XML.
From: http://code.google.com/p/k9mail/source/browse/k9mail/trunk/res/layout/account_setup_basics.xml?r=1314
<RelativeLayout
android:layout_marginTop="-45dip"
android:padding="0dip"
android:layout_alignParentBottom="true"
android:gravity="bottom|right"
android:background="#android:drawable/bottom_bar"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<Button
android:id="#+id/manual_setup"
android:text="#string/account_setup_basics_manual_setup_action"
android:minWidth="#dimen/button_minWidth"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_marginBottom="-4dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="false"
/>
<Button
android:id="#+id/next"
android:text="#string/next_action"
android:minWidth="#dimen/button_minWidth"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:drawableRight="#drawable/button_indicator_next"
android:layout_marginBottom="-4dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="false"
/>
</RelativeLayout>

Categories

Resources