Professional Documents
Culture Documents
Agenda
ViewFlipper
SlidingDrawer
TabLayout
ViewFlipper
ViewFlipper
<ViewFlipper
android:id="@+id/myViewFlipper"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
</ViewFlipper>
ViewFlipper
<ViewFlipper
android:id="@+id/myViewFlipper"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
</ViewFlipper>
Here I used
RelativeLayouts, but you
can place any widget you
want in here.
ViewFlipper
<ViewFlipper
android:id="@+id/myViewFlipper"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="match_parent"
android:layout_height=wrap_content" />
<TextView
android:layout_width="match_parent"
android:layout_height=match_parent
/>
</ViewFlipper>
ViewFlipper
ViewFlipper flipper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
flipper = (ViewFlipper) findViewById(R.id.viewFlipper1);
flipper.setFlipInterval(500);
flipper.startFlipping();
}
ViewFlipper
ViewFlipper flipper;
@Override
public void onCreate(Bundle savedInstanceState) { Here we set the flipper to
flip every 500 milliseconds
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
flipper = (ViewFlipper) findViewById(R.id.viewFlipper1);
flipper.setFlipInterval(500);
flipper.startFlipping();
}
ViewFlipper
ViewFlipper flipper;
@Override
public void onCreate(Bundle savedInstanceState) { Here we set the flipper to
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
flipper.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
flipper.showNext();
}
});
}
FrameLayout
FrameLayout
Example:
SlidingDrawer
SlidingDrawer
android:handle
android:content
android:orientation
o "vertical" or "horizontal"
android:allowSingleTap
o "true" or "false"
o allow the user to open the drawer by tapping on the
handle?
open()
close()
setOnDrawerScrollListener(OnDrawerScrollListener)
setOnDrawOpenListener(OnDrawerOpenListener)
setOnDrawerCloseListener(OnDrawerCloseListener)
TabLayout
It is used to wrap multiple activities into a single window
navigate through the activities using tabs
TabLayout - Anatomy
ACTIVITY
TabHost
o container holding TabWidget and
a FrameLayout
TabWidget
o row of tab buttons
FrameLayout
o container holding the tab contents
o each tab content is a child of
FrameLayout
TABHOST
TABWIDGET
FRAMELAYOUT
TAB CONTENT
TabLayout - XML
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
ACTIVITY
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">
<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" />
</LinearLayout>
</TabHost>
TABHOST
TABWIDGET
FRAMELAYOUT
TAB CONTENT
TabLayout - XML
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
ACTIVITY
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">
TABHOST
TABWIDGET
FRAMELAYOUT
TAB CONTENT
<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" />
</LinearLayout>
</TabHost>
TabLayout
TabLayout
public class TabLayoutExampleActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec;
Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class);
spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent);
tabHost.addTab(spec);
intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class);
spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent);
tabHost.addTab(spec);
}
TabLayout
extend TabActivity
TabLayout
public class TabLayoutExampleActivity extends TabActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec;
Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class);
spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent);
tabHost.addTab(spec);
intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class);
spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent);
tabHost.addTab(spec);
}
TabLayout
public class TabLayoutExampleActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost (which was defined
in XML)
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class);
spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent);
tabHost.addTab(spec);
intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class);
spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent);
tabHost.addTab(spec);
}
TabLayout
public class TabLayoutExampleActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabLayout
public class TabLayoutExampleActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
The TabSpec tells the TabHost
TabLayout
public class TabLayoutExampleActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
TabLayout
public class TabLayoutExampleActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec
spec;
Refer to this TabActivity's
TabLayout
public class TabLayoutExampleActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
TabLayout
public class TabLayoutExampleActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
TabLayout
public class TabLayoutExampleActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
TabLayout
public class TabLayoutExampleActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
TabLayout
public class TabLayoutExampleActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Add
the tab to the tabHost,
Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class);
it will now show up in the UI
spec = tabHost.newTabSpec("linear layout").setIndicator("Linear", null).setContent(intent);
tabHost.addTab(spec);
Intent intent = new Intent(TabLayoutExampleActivity.this, TableLayout.class);
spec = tabHost.newTabSpec("table layout").setIndicator("Table",null).setContent(intent);
tabHost.addTab(spec);
}
TabLayout
public class TabLayoutExampleActivity extends TabActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent = new Intent(TabLayoutExampleActivity.this, LinearLayout.class);
TabLayout - Rules
setCurrentTab(int)
o make this tab the active tab, making it visible in the
UI
setOnTabChangedListener(OnTabChangedListener)
o react to when the active tab changes