I want to reuse my tabs like footer for each activities in my application.
I'm using this code
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_above="#android:id/tabs" />
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
</TabHost>
and I want to add components like ListView, Button etc on top of my tabs for each layout. How can I manage this?
I've done something similar by extending a common base activity, in which I've overriden the method setContentView.
abstract public class BaseActivity extends Activity {
#Override
public void setContentView(View view) {
// get master
LayoutInflater inflater = LayoutInflater.from(this);
// this is the master view with a container and the footer, you can
// as well add the header
RelativeLayout rlMasterView = (RelativeLayout) inflater.inflate(R.layout.master, null);
rlMasterView.addView(view);
super.setContentView(rlMasterView);
}
}
The setContentView creates the footer and attaches it to the view that I'm setting in each activity.
I could as well just use the include tag in each layout.
<include src="footer" />
Related
I am using Tabbed Activity and I have three tabs with corresponding fragments. Now I want to dispay a footer that displays on every fragment when I change the Tab. Is this possible?? Please give me an simple example
Footer layout u will paste into Tabbed activity layout below tab host xml
like
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TabHost
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TabHost>
<LinearLayout
android:id="#+id/footer"
android:layout_below="#android:id/tabs"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</LinearLayout>
</RelativeLayout>
After that change view in footer based on tab selection using like this
tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() {
#Override
public void onTabChanged(String s) {
//Add view into footer or hide
}
});
I currently have a listview that has a header and footer attached. I am now trying to animate the items within the list itself, but when I apply a LayoutAnimationController to to the listview, the header is also animated. Is there a way to apply the animation to the whole list without affecting the header?
I have currently already tried the solution at Can LayoutAnimationController animate only specified Views by making a LinearLayout subclass that checks for animatable, but the header is still animating in with the rest of the items.
public class AnimationAverseLinearLayout extends LinearLayout {
private boolean mIsAnimatable = true;
public AnimationAverseLinearLayout(Context context) {
super(context);
}
public AnimationAverseLinearLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setAnimatable(boolean isAnimatable) {
if(!isAnimatable)
clearAnimation();
mIsAnimatable = isAnimatable;
}
#Override
public void startAnimation(Animation animation) {
if(mIsAnimatable) {
super.startAnimation(animation);
}
}
}
....
//in onCreateView
ListView listView = (ListView) v.findViewById(android.R.id.list);
listView.setLayoutAnimation(Animations.animateListView(listView.getContext()));
header = (com.yardi.hud.inspections.util.AnimationAverseLinearLayout) inflater.inflate(R.layout.fragment_case_search_header, null, false);
header.setAnimatable(false);
listView.addHeaderView(header);
...
SearchAdapter adapter = new SearchAdapter(results);
setListAdapter(adapter);
I had the same problem described above - the animation was being applied to the ListView header as well as list rows. I solved this problem with help from this answer. I subclassed the outermost View of my header (in my case a FrameLayout) and overrode the animation methods to take no action. For example:
list_header.xml:
<my.project.NonAnimatingFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
...
>
<!-- other views in your header -->
...
</my.project.NonAnimatingFrameLayout>
and
package my.project
public class NonAnimatingFrameLayout extends FrameLayout {
...
#Override
public void setAnimation(Animation animation) {
// do nothing
}
The animation method you need to override my vary depending on the type of your outermost view.
I try like this if you want just look this xml file,
i declare header and footer separate & Listview separate in this if you want you can Animate listview . header and footer will not get animate.
if you give header and footer Animate then it will also animate...
<?xml version="1.0" encoding="utf-8"?>
<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" >
<!-- Header aligned to top -->
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#FC9"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Fixed Header"
android:textColor="#000"
android:textSize="20sp" />
</RelativeLayout>
<!-- Footer aligned to bottom -->
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#FC0"
android:gravity="center" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Fixed Footer"
android:textColor="#000"
android:textSize="20sp" />
</RelativeLayout>
<!-- LIstview Item below header and above footer -->
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/footer"
android:layout_alignParentLeft="true"
android:layout_below="#+id/header" >
</ListView>
</RelativeLayout>
Not really the best solution, but would it be an alternative to for exemple:
create a container view (LinearLayout with vertical orientation)
add your header view
add your ListView
add a footer view
I mean, header and footer would be independent of your list component and would be a quick fix. Isn't it? You'd still being able to control header/footer visibility, for example, just by setting visibility as View.GONE.
Also 1, is there any other method you could implement? I mean, canAnimate or something like that?
Also 2, how is your getView method implemented.
Just providing a quick example of what I've explained:
<!-- Scrollable container -->
<ScrollView
android:id="#+id/scrollContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Container view -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/list"
android:orientation="vertical">
<!-- Header view -->
<TextView
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/header_text" />
<!-- LinearLayout acting as ListView -->
<LinearLayout
android:orientation="vertical"
android:id="#+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Insert rows into the fake list -->
<TextView
android:id="#+id/row_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/row_item" />
</LinearLayout>
<!-- Footer view -->
<TextView
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/footer_text" />
</LinearLayout>
</ScrollView>
I believe the problem got solved now :)
I created a menuView.xml layout to be in all of the layouts of my activity. This layout has one column on each border and a title bar like this:
ComposeView http://img845.imageshack.us/img845/2121/d6zp.png
I insert this layout in the other layouts this way:
<!-- Show menu -->
<com.example.MenuView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
But if one of the layouts has full screen view, part of this view gets covered by the MenuView, so...
How could I tell to this view to adapt its size to the blank space inside the MenuView to not get covered by it?
UPDATE -- full XML included
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="#drawable/degradado">
<!-- Show menu -->
<com.example.MenuView
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout
android:id="#+id/Left_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true" >
//Here go buttons, views, etc...
</RelativeLayout>
<RelativeLayout
android:id="#+id/Right_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true" >
//Here go buttons, views, etc...
</RelativeLayout>
What happens here is that these 2 Relative layouts get covered by the MenuView (The darkest gre borders and the top black bar), and the ideal way would be that these 2 layouts get fitted to the blank space (the clearest gray).
I can solve this setting margin sizes to the Relative layouts to fit inside of it, but i know this is not the best way to do it, so I don't know if there is another way.
I think the best way to solve your issue is with inheritance.
If you define an Activity that can be used as a template for all your fleshed out Activitys to add their content to.
I don't know what you custom menu is 'made of' but as a simple example:
Create a basic Activity with code:
public class ActivityWithMenu extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_with_menu_layout);
}
}
and xml:
<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"
tools:context=".ActivityWithMenu" >
<TextView
android:layout_width="match_parent"
android:layout_height="20dip"
android:background="#ff000000"
android:textColor="#ffffffff"
android:text="Main Menu Title Bar"
android:id="#+id/mainmenutitle" />
<LinearLayout
android:layout_width="20dip"
android:layout_height="match_parent"
android:layout_below="#+id/mainmenutitle"
android:layout_alignParentLeft="true"
android:background="#ff999999"
android:orientation="vertical"
android:id="#+id/lefthandmenu" />
<LinearLayout
android:layout_width="20dip"
android:layout_height="match_parent"
android:layout_below="#+id/mainmenutitle"
android:layout_alignParentRight="true"
android:background="#ff999999"
android:orientation="vertical"
android:id="#+id/righthandmenu" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="#+id/righthandmenu"
android:layout_toRightOf="#+id/lefthandmenu"
android:layout_below="#+id/mainmenutitle"
android:orientation="vertical"
android:id="#+id/activitycontent"
/>
</RelativeLayout>
Then create your xml for a specific Activity, in this case a simple 'Hello World' layout:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff00ff00"
android:text="Hello World!"
/>
</LinearLayout>
</ScrollView>
But now when you write the code for this Activity, extend 'ActivityWithMenu' instead of the Activity class direct and inflate this xml layout as follows:
public class Activity1 extends ActivityWithMenu
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
LinearLayout ll = (LinearLayout)findViewById(R.id.activitycontent);
ScrollView sv = (ScrollView)this.getLayoutInflater().inflate(R.layout.activity1_layout, ll, false);
ll.addView(sv);
}
}
I have added the code for making the Activity fullscreen here instead of in the parent ActivityWithMenu class assuming that you wouldn't want them all displayed that way but you could move it into the parent class if appropriate.
Hope this helps.
I have multiple activities in my app and i want a slidingdrawer to appear in all the activities. I am following the approach given here.
The app starts with a black screen with the slidingdrawer handle.
Issue is that the sliding drawer is visible but the activity layout put in FarmeLayout is not visible.
The activity is there for sure. Toasts came up when the first activity loaded. So I modified my first activity to have only a button on it to go to next activity.
Next I used the direction keys on the AVD, and pressed ok which brought up the the next activity's Toast. Second activity is as well hidden.
So what am I missing???
My Sliding Drawer layout xml (LinearLayout) with farme layout at the end:
<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:orientation="horizontal"
android:gravity="center_vertical">
<SlidingDrawer
android:id="#+id/slidingDrawer"
android:handle="#+id/drawerHandle"
android:content="#+id/contentLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:persistentDrawingCache="all">
<ToggleButton
android:id="#+id/drawerHandle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxHeight="5dp"
android:textSize="14dp"
android:textStyle="italic"
android:background="#BB00FF"
android:rotation="270"
android:textOn=""
android:textOff=""/>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/contentLayout"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:contentDescription="#string/todo">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:text="#string/list_view_" />
</LinearLayout>
</SlidingDrawer>
<FrameLayout
android:id="#+id/act_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="#808080"
android:visibility="visible">
</FrameLayout>
</LinearLayout>
DrawerActivity java code:
public abstract class DrawerActivity extends Activity
{
protected LinearLayout fullLayout;
protected FrameLayout actContent;
#Override
public void setContentView(final int layoutResID)
{
fullLayout= (LinearLayout) getLayoutInflater().inflate(R.layout.act_layout, null); // Your base layout here
actContent= (FrameLayout) fullLayout.findViewById(R.id.act_content);
getLayoutInflater().inflate(layoutResID, actContent, true); // Setting the content of layout your provided to the act_content frame
super.setContentView(fullLayout);
}
}
In all my activitie files I have put setContentView(R.layout.XXXXXXXX); in the onCreate method.
So how do I make the activities visible?? What am I doing wrong??
I tried putting in the following but to no effect
actContent.setVisibility(layoutResID);
or
actContent.setVisibility(View.VISIBLE);
I have a little problem using Tabs with Views.
First I just copied the sample code where Tabs are used with activitys:
My LayoutFile looks like this:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
And this is my Java-code:
public class MyActivity extends TabActivity{
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState)
setContentView(R.layout.main);
TabHost tH = getTabHost();
Indent intent = new Intent().setClass(this, AnotherActivity.class);
// Initialize a TabSpec for each tab and add it to the TabHost
//TextView Test = new TextView(this);
//Test.setText("test");
tH.addTab(tH.newTabSpec("t1").setIndicator("Tab1").setContent(intent));
tH.setCurrentTab(0);
}
}
And this works as expected.
But when I uncomment the TextView-lines and call setContent(Test.getId()) instead of setContent(intent), the app crashes.
I also tried to create a textview in the layoutfile, and call setContent(R.id.test),
that also makes it crash.
So this is one problem.
The seccond point is. I do not want to use activitys, because i want to be able to call methods on those classes, which shall represent the Tab-content.
So my original idea is, to derive some classes from view. 1 for each tab, and pass their ids. But therefor the codesample above needs to work first.
greetings Uzaku
I know you said you tried a TextView in the layout file but this should work...
Change the FrameLayout section as follows...
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<TextView
android:id="#+id/test"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="TEST" />
</FrameLayout>
Then in your code do the following...
tH.addTab(tH.newTabSpec("t1").setIndicator("Tab1").setContent(R.id.test));