How can i create Horizontal and Vertical tabs in android? - android

I am writing a code in Android to create Horizontal and Vertical tabs. In my code , i only able to create Horizontal tab , which is default.
XML Code
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccccc"
android:padding="5dp">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccccc"
android:padding="5dp">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:padding="5dp">
<GridView
android:id="#+id/gridView1"
android:numColumns="10"
android:gravity="center"
android:layout_marginLeft="0dp"
android:layout_marginTop="0dp"
android:stretchMode="columnWidth"
android:paddingLeft="3dp"
android:paddingRight="3dp"
android:horizontalSpacing="3dp"
android:verticalSpacing="3dp"
android:layout_width="1600dp"
android:layout_height="fill_parent"/>
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>
Java Code :
package com.example.tabsabc;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.app.Fragment;
import android.app.TabActivity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TabHost;
import android.widget.TabWidget;
import android.widget.TextView;
public class MainActivity extends TabActivity implements TabHost.TabContentFactory {
ArrayList<String> names;
GridView gd;
BoxGrid gdv;
TabWidget tb1;
TabWidget tb2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gd = (GridView)findViewById(R.id.gridView1);
//tb1 = (TabWidget)findViewById(R.id.tabs1);
names = new ArrayList<String>();
final TabHost tabHost = getTabHost();
for (int i=1; i <= 10; i++) {
String name = "Tab " + i;
tabHost.addTab(tabHost.newTabSpec(name)
.setIndicator(name)
.setContent(this));
}
for(int i1=0;i1<150;i1++)
{
names.add(String.valueOf(i1));
}
ArrayAdapter gdv = new ArrayAdapter(this, android.R.layout.simple_list_item_1, names);
gd.setAdapter(gdv);
}
/** {#inheritDoc} */
public View createTabContent(String tag) {
final TextView tv = new TextView(this);
tv.setText("Content for tab with tag " + tag);
return tv;
}}
So, this is my above code and i can't find the place where can i add the vertical tab in the XML layout. I don't find any technique to do this.
Please let me know , suggest me some good solution.

I'll leave this here, because that's a more comfortable way than trying to style the TabWidget:
Looking for a universal TabHost style that will work on Android, HTC Sense, Samsung, etc. skins
But even better, use Fragments inside a ViewPager and not the old TabHost + TabWidget approach. It's the recommended way of doing Tabs in Android nowadays anyway.

Related

Viewpager in Scrollview dose not work

In my project i have a ViewPager that display some image horizontally. I want to put it in a ScrollView but when I do this it dose not work.
here is my XML :
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<com.pixelcan.inkpageindicator.InkPageIndicator
android:id="#+id/indicator"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
app:ipi_animationDuration="320"
app:ipi_currentPageIndicatorColor="#android:color/black"
app:ipi_dotDiameter="8dp"
app:ipi_dotGap="8dp"
app:ipi_pageIndicatorColor="#android:color/darker_gray" />
<android.support.v4.view.ViewPager
android:id="#+id/viewpager"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
and this is my main :`
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import com.pixelcan.inkpageindicator.InkPageIndicator;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
ViewPager viewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = findViewById(R.id.viewpager);
InkPageIndicator inkPageIndicator = (InkPageIndicator) findViewById(R.id.indicator);
ArrayList<Model> values = new ArrayList<>();
values.add(new Model("image 1", R.drawable.baby1));
values.add(new Model("image 2", R.drawable.baby2));
values.add(new Model("image 3", R.drawable.baby3));
values.add(new Model("image 4", R.drawable.baby4));
View_Pager_Adapter adapter = new View_Pager_Adapter(values);
viewPager.setAdapter(adapter);
inkPageIndicator.setViewPager(viewPager);
}
}
I search a lot about this but non of them was useful for me.
please help me
Thanks

Error in MainActivity when implementing TabActivity

i want a page with text on top(EditText) then image (in FragmentLayout) and then two tabs below that image.
my output is not showing any tab in output but i have written code to implement tabs.
this code is notshowing any error and in output i mam not getting any tab in output
i am not getting correct output and this is not even showing any error
i tried it without extending TabActivity also (only with extens Activity) but still output is same whose image is loaded above
Code of activity_main.xml is
<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="vertical"
tools:context=".MainActivity" >
<TextView
android:id="#+id/tbol"
android:layout_width="250dp"
android:layout_height="30dp"
android:text="#string/heading"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#F00"
android:textSize="25sp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="160dp"
android:background="#drawable/leaf" >
</FrameLayout>
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
code of MainActivity.java is
package com.example.tabhost;
import android.os.Bundle;
import android.app.TabActivity;
import android.content.Intent;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
#SuppressWarnings("deprecation")
public class MainActivity extends TabActivity {
TabHost th;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
th=getTabHost();
//For desc tab
TabSpec descspec=th.newTabSpec("Description");
descspec.setIndicator("Description", null);
Intent firstintent=new Intent(this, DecsriptionTab.class);
descspec.setContent(firstintent);
//For Information Tab
TabSpec infospec=th.newTabSpec("Information");
infospec.setIndicator("Information", null);
Intent secondintent=new Intent(this, Info_Tab.class);
descspec.setContent(secondintent);
}
}
this is code of 2 .xml files
desc_layout.xml
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:text="This is desc tab"
android:padding="15dp"
android:textSize="18sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
info_layout
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView android:text="This is info tab"
android:padding="15dp"
android:textSize="18sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
This is code of corresponding java files
DecsriptionTab.java
package com.example.tabhost;
import android.app.Activity;
import android.os.Bundle;
public class DecsriptionTab extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.desc_layout);
}
}
Info_Tab.java
package com.example.tabhost;
import android.app.Activity;
import android.os.Bundle;
public class Info_Tab extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.info_layout);
}
}

Want to diaplay tabbar and listview in my launch activity

I want to display the tab bar and listview but when my main activity launched then my tab bar gets hided... so tell me what is the problem in my xml or my src file.
My problem is: My tab bar is not showing and only listview is showing on the full screen.
Here my lisview appears first and behind that my tab bar slightly visible.
Main Activity:(Here I am displaying tab host)
package com.example.testlist;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import android.app.Activity;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabHost.OnTabChangeListener;
public class MainActivity extends TabActivity implements OnTabChangeListener{
/*******************************/
//Test for tab bar
TabHost tabHost;
/*******************************/
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
/*setContentView(R.layout.list_view_layout);
ListView listview=(ListView)findViewById(R.id.listView1);
*/
setContentView(R.layout.layout_tab_bar);
// Get TabHost Refference
tabHost = getTabHost();
// Set TabChangeListener called when tab changed
tabHost.setOnTabChangedListener(this);
TabHost.TabSpec spec;
Intent intent;
/************* TAB1 (home)************/
// Create Intents to launch an Activity for the tab (to be reused)
intent = new Intent().setClass(this, HomeTab.class);
spec = tabHost.newTabSpec("First").setIndicator("")
.setContent(intent);
//Add intent to tab
tabHost.addTab(spec);
/************* TAB2(alerts) ************/
intent = new Intent().setClass(this, Tab2.class);
spec = tabHost.newTabSpec("Second").setIndicator("")
.setContent(intent);
tabHost.addTab(spec);
/************* TAB3 (newsletters)************/
intent = new Intent().setClass(this, Tab3.class);
spec = tabHost.newTabSpec("Third").setIndicator("")
.setContent(intent);
tabHost.addTab(spec);
/************* TAB4(calendars) ************/
intent = new Intent().setClass(this, Tab4.class);
spec = tabHost.newTabSpec("Fourth").setIndicator("")
.setContent(intent);
tabHost.addTab(spec);
/************* TAB5 (more)************/
intent = new Intent().setClass(this, Tab5.class);
spec = tabHost.newTabSpec("Fifth").setIndicator("")
.setContent(intent);
tabHost.addTab(spec);
// Set drawable images to tab
tabHost.getTabWidget().getChildAt(0).setBackgroundResource(R.drawable.homeicon);
tabHost.getTabWidget().getChildAt(1).setBackgroundResource(R.drawable.alert_small_icon);
tabHost.getTabWidget().getChildAt(2).setBackgroundResource(R.drawable.newsl);
tabHost.getTabWidget().getChildAt(3).setBackgroundResource(R.drawable.menu_calendar);
tabHost.getTabWidget().getChildAt(4).setBackgroundResource(R.drawable.more_big);
// Set Tab1 as Default tab and change image
tabHost.getTabWidget().setCurrentTab(0);
}
#Override
public void onTabChanged(String tabId) {
}
}
HomeTab.java:(this class loads the content of first tab)
This class loads the content for the home tab where the contents related to home tab appears but my tab bar gets hided here.
package com.example.testlist;
import java.util.ArrayList;
import android.R.anim;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.ListView;
public class HomeTab extends Activity{
MyCustomAdapter myCustomAdapter;
Context context=HomeTab.this;
String optionName[]=new String[] {"Alerts","Events","Newsletters","News","Parent Info","Logins","Parent Teacher Interviews","Flexi School LunchOrder","Contact US","Kool Content"};
// String text2[]=new String[] {"sub1","sub2","sub3","sub4","sub1","sub2","sub3","sub4","sub1","sub2"};
//int image[]=new int[] {R.drawable.alert_small_icon,R.drawable.events,R.drawable.newsletter,R.drawable.newsletter,R.drawable.arrow_24,R.drawable.arrow_24,R.drawable.arrow_24,R.drawable.arrow_24,R.drawable.arrow_24,R.drawable.arrow_24};
int imageArrow[]=new int[]{R.drawable.right_arrow};
ArrayList<ListModel> mylist=new ArrayList<ListModel>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_view_layout);
ListView listview=(ListView)findViewById(R.id.listView1);
getDatainList();
listview.setAdapter(new MyCustomAdapter(context, mylist));
listview.setBackgroundColor(Color.WHITE);
}
private void getDatainList()
{
for(int i=0;i<10;i++)
{
ListModel li=new ListModel();
li.setOptionName(optionName[i]);
// li.setImage(image[i]);
li.setImageArrow(R.drawable.arrow);
mylist.add(li);
}
}
}
layout_tab_bar.java(This class displays the tab host and used in Main Activity)
<?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">
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
</TabHost>
listview_layout.xml:
This file shows how the listview is added:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<!-- Header Starts -->
<RelativeLayout
android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<!-- Logo Start -->
<ImageView
android:id="#+id/menuimage"
android:layout_width="wrap_content"
android:layout_height="15dp"
android:src="#drawable/menuicon_big" />
<TextView
android:id="#+id/txt_Home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:gravity="center"
android:text="HOME"
android:textColor="#android:color/black"
android:textSize="20sp" />
<View
android:layout_width="match_parent"
android:layout_height="1dp" />
</RelativeLayout>
<!-- Header Ends -->
<ImageView
android:id="#+id/stbernard"
android:layout_width="match_parent"
android:layout_height="60dp"
android:scaleType="fitXY"
android:src="#drawable/stbernard" />
<!-- <ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.01"
android:divider="#android:color/transparent"
android:dividerHeight="10.0sp" >
</ListView> -->
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</ListView>
</LinearLayout>
single_row.xml:
This file shows how the content inside listview appears for each item
<?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="wrap_content"
android:id="#+id/rel">
<ImageView
android:id="#+id/imageviewArr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="21dp"
android:src="#drawable/arrow"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<View android:id="#+id/testView"
android:layout_height="1dp"
android:layout_width="match_parent"
android:background="#android:color/black"
/>
<TextView
android:id="#+id/txt_Options"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:gravity="center"
android:text="text1"
android:textColor="#android:color/black"
android:textSize="20sp"
android:paddingLeft="2dp" />
</RelativeLayout>
it's because you declare the height of the content to fill the parent here
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
that's why the tabs is being overlapped by the content, what you need is android:layout_weight, so you need to change it to this
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
android:layout_weight will fill all the remaining space of the parent view so it won't overlap with each other

How do i display a ListView with a header below another ListView all in Tab1 of TabHost?

I'm trying to put a ListView below another ListView in the first tab using tabhost.
The reason i want it like this is because i want to divide a list of trading cards by type so i guess creating sections or whatever.
Here is my .xml:
<?xml version="1.0" encoding="utf-8"?>
<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="vertical" >
<TextView
android:id="#+id/banlistdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:text="Banlist Date: March, 2013"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFFFF" />
<TabHost
android:id="#+id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/banlistdate" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ListView
android:id="#+id/fLV1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF8B53"
tools:listheader="#layout/banlist_header_effectmonsters" >
</ListView>
<ListView
android:id="#+id/fLV2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#a086b7"
tools:listheader="#layout/banlist_header_fusionmonsters" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/flv3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</LinearLayout>
Here is my the main java file to start the tabs and setup the ListViews:
package cybertech.productions.yugiohlibrary;
import java.util.ArrayList;
import java.util.Arrays;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
public class Banlist extends Activity implements OnClickListener {
TabHost th;
Initializers initialMngr;
ArrayAdapter<String> listAdapter;
ListView forbiddenEMListView, forbiddenFListView;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.banlist);
th = (TabHost) findViewById(R.id.tabhost);
th.setup();
TabSpec specs = th.newTabSpec("tag1");
specs.setContent(R.id.tab1);
specs.setIndicator("Forbidden");
th.addTab(specs);
specs = th.newTabSpec("tag2");
specs.setContent(R.id.tab2);
specs.setIndicator("Semi-Limited");
th.addTab(specs);
specs = th.newTabSpec("tag3");
specs.setContent(R.id.tab3);
specs.setIndicator("Limited");
th.addTab(specs);
th.setCurrentTab(0);
// #BEGIN: Tab 1 ListViews
//Setup the "forbidden" ListView(s);
// ListView 1: Effect Monsters
forbiddenEMListView = (ListView) findViewById(R.id.fLV1);
ArrayList<String> forbiddenEMList = new ArrayList<String>();
forbiddenEMList.addAll(Arrays.asList(initialMngr.forbiddenEM));
listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, forbiddenEMList);
View effectMon_header = View.inflate(this, R.layout.banlist_header_effectmonsters, null);
forbiddenEMListView.addHeaderView(effectMon_header);
forbiddenEMListView.setAdapter(listAdapter);
// ListView 2: Fusion Monsters
forbiddenFListView = (ListView) findViewById(R.id.fLV2);
ArrayList<String> forbiddenFList = new ArrayList<String>();
forbiddenFList.addAll(Arrays.asList(initialMngr.forbiddenF));
listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, forbiddenFList);
View fusion_header = View.inflate(this, R.layout.banlist_header_fusionmonsters, null);
forbiddenFListView.addHeaderView(fusion_header);
forbiddenFListView.setAdapter(listAdapter);
// #END: Tab 1 ListViews
}
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
}
Thanks for any help.
You want to use an ExpandableListView. Use the group views to label the different categories or sections. Since you are using Arrays to back your lists, SimpleExpandableListAdapter should fit the bill nicely.

Android code to zoom and pan a Relative layout which contains text boxes, buttons, spinners, etc

I have zoomed into the layout easily but I also want to scroll the zoomed layout. I have been able to zoom but I want to also have scrolling after I zoom so that I can edit the values of the Widgets
Is there any way to do this ?
import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
public class MainActivity extends TabActivity {
View mainview;
int zoomed = 0;
TabHost th;
TabSpec one;
TabSpec two;
TabSpec three;
TabSpec four;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mainview = (RelativeLayout) findViewById(R.id.relLayout1);
th = getTabHost();
th.setup();
one = th.newTabSpec("One");
two = th.newTabSpec("Two");
three = th.newTabSpec("Three");
four = th.newTabSpec("Four");
one.setIndicator("One");
two.setIndicator("Two");
three.setIndicator("Three");
four.setIndicator("Four");
Intent a = new Intent(this, first.class);
Intent b = new Intent(this, second.class);
Intent c = new Intent(this, third.class);
Intent d = new Intent(this, fourth.class);
one.setContent(a);
two.setContent(b);
three.setContent(c);
four.setContent(d);
th.addTab(one);
th.addTab(two);
th.addTab(three);
th.addTab(four);
mainview.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
mainview.setPivotX(100);
mainview.setPivotY(100);
if (zoomed == 0) {
mainview.setScaleX(2f);
mainview.setScaleY(2f);
zoomed=1;
}
else{
mainview.setScaleX(1f);
mainview.setScaleY(1f);
zoomed=0;
}
}
});
}
}
And this is my layout :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/relLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="220dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/tab1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
<LinearLayout
android:id="#+id/tab4"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
</RelativeLayout>

Categories

Resources