Common View through Activities - android

I need to create multiple activities that will have a bar at the bottom of the screen. This bar contains three functions that are common to the activities. Can i keep the bar constantly on screen and switch through activities?
One way could be to load different fragments on the same activity, and let the bar be below the fragments.
But is it possible to switch between activities, without recreating the bar every time a new activity opens?

Possible option:
You have to create bottom layout bottomlayout.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="#+id/toolBarText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:background="#android:color/transparent"
android:layout_centerInParent="true"
android:text="TOOLBAR TEXT"
android:textColor="#FFFFFF"
android:textSize="15dp" />
</RelativeLayout>
Include bottomlayout in every xml layout of activity.
<include layout="#layout/bottomlayout"/>

Fragments, is one way of doing it. Isn't there any other.

Related

Create multi level scrollabe menu in Android (like Camera360 app)

I'm building a photo effect app for android, and i want to create a menu like Camera360 app's menu (please view menu image link):
How can i create menu like this or support library?
Thanks
You can recreate the menu at the bottom using a ScrollView that holds a row of buttons. The new menu after the click in your image looks like another Activity with the same layout. I recreated a rough version of it like so:
<HorizontalScrollView android:layout_height="50dp" android:layout_width="match_parent" android:scrollbarSize="0dp">
<LinearLayout android:layout_height="50dp" android:layout_width="wrap_content">
<Button android:id="#+id/btn1" android:layout_height="50dp" android:layout_width="50dp" android:text="op1" />
<Button android:id="#+id/btn2" android:layout_height="50dp" android:layout_width="50dp" android:text="op2" />
...
</LinearLayout>
</HorizontalScrollView>
Tinker with the parameters and visuals and you're all set!
In order to make it 'multi-level' you can add onClickListeners that launch an acquitted activity according to your menu tree. For communication between activities, you can use startActivityForResult.

Different view arrangement when it's centered in relative layout and overlapped

I'm making custom view for an Action Bar. There have to be centered title, some action buttons at the right and navigation drawer button/back with title at the left.
I use RelativeLayout to place all elements, like so (this is demonstrating variant of real layout):
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/actionBarHomeContainer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:clickable="true">
<ImageView
android:id="#+id/actionBarHomeImage"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:duplicateParentState="true"/>
<TextView
android:id="#+id/actionBarHomeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:duplicateParentState="true"/>
</LinearLayout>
<TextView
android:id="#+id/actionBarTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
<LinearLayout
android:id="#+id/actionBarOptionsContainer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_alignParentRight="true">
<!--Action items will be added here pragmatically-->
</LinearLayout>
</RelativeLayout>
In most screen cases it's all OK (green picture), but when I deal with tight screens, my title is overlapping by home label (yellow picture). Keep in mind the this is only demonstrating situation, real items smaller than drew ones and case like this is rare. So my aim is in case of title is overlapped just place it in center of remain space between actionBarHomeContainer and actionBarOptionsContainer (blue picture). Is it possible somehow and what other solutions you may suggest to me?
Thanks.
There's an official and very easy solution to your problem: Don't mimic UI elements from other platforms
Don't use labeled back buttons on action bars
Other platforms use an explicit back button with label to allow the user to navigate up the application's hierarchy. Instead, Android uses the main action bar's app icon for hierarchical navigation and the navigation bar's back button for temporal navigation. For more information, please review the Navigation pattern.
Follow this guideline to provide a consistent navigation experience across the platform.
Android action bar with up caret vs. iOS labeled "Back" button.

Android Design Principle for most used fragment

I am designing an Android Application in Android where there is one entry point activity which has 3 TABS and I need to allow user to update his status from any of the Tabs. So, I have created a StatusFragment in activity_main.xml. So it is available at the top of each fragment in tabs. I just wanted to ask if there is a better way of doing this. I want to minimize the screen estate used by Status Fragment. Here goes my StatusFragment's layout xml.
<LinearLayout 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:divider="#android:drawable/divider_horizontal_dark"
android:showDividers="middle"
android:dividerPadding="#dimen/list_view_item_image_padding"
android:orientation="horizontal"
android:padding="#dimen/list_view_item_image_padding">
<TextView
android:id="#+id/tv_status"
android:padding="#dimen/list_view_item_image_padding"
android:layout_margin="#dimen/list_view_item_image_margin"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:maxLines="2"
android:ellipsize="end"
android:scrollHorizontally="true"
android:layout_weight="1"
android:text="#string/hello_blank_fragment" />
<ImageButton
android:id="#+id/iv_edit_status"
android:padding="#dimen/list_view_item_image_padding"
android:layout_margin="#dimen/list_view_item_image_margin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_edit"
android:background="#drawable/list_view_button_selector"
/>
Sory for bad english. If I'm at wrong place please guide me to the right one. Any help provided will be helpful.
I have thought of doing it in a NavigationDrawer and SlidingPaneLayout but I guess these layouts are overkill for this task.
You can have the status as part of the main activity and just change the fragment corresponding to the tab inside of a frame layout:
<RelativeLayout>
<LinearLayout>
<TextView/>
<ImageButton/>
</LinearLayout>
<FrameLayout android:id="#+id/fragment_container"/>
</RelativeLayout>

Same fragments in one activity problem

I'm coding my first android app with fragments and here is my problem. I've got main activity and 3 fragments in it. All 3 fragments are the same class so all 3 fragments has the same layout. But I need every fragment to has different title in that layout. But I can't select the TextView wich I need because all these fragmtents TextViews has the same ID because of the same layout. Is there some easy way to do this.
Thanx
Given your Fragments f1, f2, f3, you could try f1.getView().findViewById(id), f2.getView().findViewById(id), f3.getView().findViewById(id) to reduce the scope of the search to only that particular fragment each time.
However, I think the point of using Fragments is to improve modularity and to avoid things like having to expose all of the views to the Activity. It can be controlled by the Fragment instead. You could have the views be resolved inside the Fragment and then give a setTitle() method on the Fragment for the Activity to use.
The ID should not matter since each class will be inflating its own instance of the layout. Try it using the same ID.
If under 'fragment' you mean an UI component you should specify different IDs for each and every component in your layout!
<LinearLayout
android:id="#+id/LinearLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#ff0000"
android:text="Header"
/>
<TextView
android:id="#+id/body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#00ff00"
android:text="Body"
/>
<TextView
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#0000ff"
android:text="Footer"
/>
</LinearLayout>
If you mean other xml fragments inside a main xml layout, you can use same ID, but in different xml fragments!

Sliding drawer in the same layout

Do you know how to achieve the same effect as winamp for android ? I want to do the similar thing. That is when I click on listview, sliding drawer popup. But so far I only can show the sliding drawer in new activity not in the same.
How can I achieve in overlap view. That is when I close the drawer, the layout is show at the front, and the sliding handle is on the layout, when I open the drawer, it covers the main layout.
Any ideas about that ?
Thanks !!
Step #1: Create a RelativeLayout
Step #2: Put the rest of your UI in the RelativeLayout
Step #3: Put the SlidingDrawer in the RelativeLayout as a later child then the rest of the UI (e.g., in layout XML, have it as the last child element of the RelativeLayout)
Children of RelativeLayout (and FrameLayout) stack on top of one another on the Z-axis (i.e., out the face of the screen). Hence, later children will overlap earlier ones. By putting your SlidingDrawer last, it will overlap everything else when opened.
Thank you CommonsWare you helped me,I do not have much reputation to vote up. Here is my sample layout...
I used it.sephiroth.slider.widget.MultiDirectionSlidingDrawer as the SlidingDrawer
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_alignParentLeft="true" android:layout_marginLeft="82dp"
android:layout_alignTop="#+id/button_open">
<Button
android:id="#+id/button_open"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="#string/open"
android:visibility="visible" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New EditText"
android:id="#+id/editText" android:layout_alignParentLeft="true" android:layout_marginLeft="114dp"
android:layout_alignParentTop="true" android:layout_marginTop="6dp"/>
</RelativeLayout>
<it.sephiroth.demo.slider.widget.MultiDirectionSlidingDrawer
xmlns:panel="http://schemas.android.com/apk/res/it.sephiroth.demo.slider"
android:id="#+id/drawer"
panel:direction="topToBottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
panel:handle="#+id/handle"
panel: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="40px"
android:src="#drawable/sliding_drawer_handle_bottom" />
</it.sephiroth.demo.slider.widget.MultiDirectionSlidingDrawer>
</RelativeLayout>

Categories

Resources