Let's take a look
How about it?
Let's analyze how this effect can be achieved?
First of all, we should note that the top several horizontal switchover functions are TabHost.
TabHost has been released successfully
Provides a window view container for tabs. This object contains two sub-objects: one group is the tag that users can select to specify the Tab page, and the other group is the FrameLayout to display the content of this Tab page. The container object is usually used instead of the value set in the child element itself. (Note: Even if you are using a single element, you 'd better put it in the ViewGroup of the container object)
Internal class
InterfaceTabHost. OnTabChangeListener
Interface defines the callback function called when the tab is changed
Interface TabHost. TabContentFactory
Tab content is generated when a tab is selected
Class TabHost. TabSpec
A separate tab. Each option card has a tab indicator, content, and tag to facilitate recording.
Common Methods
Public void addTab (TabHost. TabSpec tabSpec)
Add a tab
Parameters
TabSpec specifies how to create the indicator and content.
<? Xml version = "1.0" encoding = "UTF-8"?>
<TabHost xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent">
<LinearLayout android: id = "@ + id/tab1" android: orientation = "vertical"
Android: layout_width = "fill_parent" android: layout_height = "fill_parent">
<Button android: id = "@ + id/button" android: layout_width = "fill_parent"
Android: layout_height = "wrap_content" android: text = "switch to 3rd tags"/>
<ImageView android: layout_width = "fill_parent"
Android: layout_height = "wrap_content" android: src = "@ drawable/background" android: layout_marginTop = "30dp"/>
</LinearLayout>
</TabHost>
Import android. app. TabActivity;
Import android. content. Intent;
Import android. OS. Bundle;
Import android. view. LayoutInflater;
Import android. widget. TabHost;
Public class TableHostTest extends TabActivity {
Private TabHost tabHost = null;
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
TabHost = this. getTabHost ();
LayoutInflater inflater = LayoutInflater. from (this );
/* Pay attention to the role of true */
Inflater. inflate (R. layout. tablehost, tabHost. getTabContentView (), true );
TabHost. addTab (tabHost. newTabSpec ("tab1"). setIndicator ("interface 1"). setContent (R. id. tab1 ));
TabHost. addTab (tabHost. newTabSpec ("tab2"). setIndicator ("interface 2"). setContent (new Intent (this, SeekBarDemo. class )));
TabHost. addTab (tabHost. newTabSpec ("tab3"). setIndicator ("Interface 3"). setContent (new Intent (this, UITest4Activity. class )));
}
}
Progress bar display:
<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" android: layout_width = "fill_parent" android: layout_height = "fill_parent" android: orientation = "vertical"> <TextView android: layout_width = "fill_parent" android: layout_height = "wrap_content" android: text = "progress bar Demo"/> <ProgressBar android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: max = "1000" android: progress = "100" android: id = "@ + id/progressbar1"/> <ProgressBar style = "@ android: style/Widget. progressBar. horizontal "android: layout_marginTop =" 30dp "android: layout_width =" fill_parent "android: layout_height =" wrap_content "android: max =" 1000 "android: progress =" 500 "android: secondaryProgress = "300" android: id = "@ + id/progressbar2"/> </LinearLayout>
Import android. app. Activity;
Import android. OS. Bundle;
Import android. OS. Handler;
Import android. util. Log;
Import android. widget. ProgressBar;
Public class ProgressBarDemo extends Activity {
ProgressBar progressbar = null;
Static int I = 0;
Int progressbarMax = 0;
Handler handler = new Handler ();
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. progressbar_layout );
FindViews ();
}
Private void findViews (){
Progressbar = (ProgressBar) this. findViewById (R. id. progressbar2 );
Progressbar. setMax (1000 );
ProgressbarMax = progressbar. getMax ();
New Thread (new Runnable (){
Public void run (){
While (I <progressbarMax ){
I = doWork ();
Handler. post (new Runnable (){
Public void run (){
Progressbar. setProgress (I );
}
});
Try {
Thread. sleep (50 );
} Catch (InterruptedException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
}
}
}). Start ();
}
Public int doWork (){
Log. d ("TAG", String. valueOf (I ));
Return ++ I;
}
/* // Unavailable !!!!
Public void run (){
Log. d ("TAG", "thread starting ...");
While (I ++ <progressbarMax ){
Progressbar. setProgress (I );
Try {
Thread. sleep (50 );
} Catch (InterruptedException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
}
}
*/
}
The following uses ImageView to preview images.
Import android. app. Activity;
Import android. graphics. Bitmap;
Import android. graphics. drawable. BitmapDrawable;
Import android. OS. Bundle;
Import android. view. MotionEvent;
Import android. view. View;
Import android. view. View. OnTouchListener;
Import android. widget. ImageView;
Public class ImageViewDemo extends Activity implements OnTouchListener {
ImageView imageView1, imageView2;
Protected void onCreate (Bundle savedInstanceState ){
// TODO Auto-generated method stub
Super. onCreate (savedInstanceState );
This. setContentView (R. layout. imageview_layout );
FindViews ();
}
Private void findViews (){
ImageView1 = (ImageView) findViewById (R. id. img1 );
ImageView2 = (ImageView) findViewById (R. id. img2 );
ImageView1.setOnTouchListener (this );
}
Public boolean onTouch (View v, MotionEvent event ){
Float size = 412/320;
Int x = (int) (event. getX () * scale );
Int y = (int) (event. getY () * scale );
// Try to solve the Boundary Problem
Int width = (int) (100 * scale );
Int height = (int) (100 * scale );
BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView1.getDrawable ();
ImageView2.setImageBitmap (Bitmap. createBitmap (bitmapDrawable. getBitmap (),
X, y, width, height ));
Return false;
}
}
<? 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 = "match_parent"
Android: orientation = "vertical">
<ImageView
Android: id = "@ + id/img1"
Android: layout_width = "fill_parent"
Android: layout_height = "300dp"
Android: background = "# cccccc"
Android: src = "@ drawable/pig"/>
<ImageView
Android: id = "@ + id/img2"
Android: layout_width = "100dp"
Android: layout_height = "100dp"
Android: background = "# cccccc"
Android: scaleType = "fitStart"
Android: layout_marginTop = "20dp"
/>
</LinearLayout>
Controls for volume adjustment:
<? 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 = "match_parent"
Android: orientation = "vertical">
<SeekBar
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: max = "1000"
Android: id = "@ + id/seekbar"
/>
</LinearLayout>
Import android. app. Activity;
Import android. OS. Bundle;
Import android. util. Log;
Import android. widget. SeekBar;
Import android. widget. SeekBar. OnSeekBarChangeListener;
Public class SeekBarDemo extends Activity implements OnSeekBarChangeListener {
SeekBar seekbar = null;
Protected void onCreate (Bundle savedInstanceState ){
// TODO Auto-generated method stub
Super. onCreate (savedInstanceState );
This. setContentView (R. layout. seekbar_layout );
FindViews ();
}
Private void findViews (){
Seekbar = (SeekBar) this. findViewById (R. id. seekbar );
Seekbar. setOnSeekBarChangeListener (this );
}
@ Override
Public void onProgressChanged (SeekBar seekBar, int progress,
Boolean fromUser ){
Log. d ("TAG", "changed:" + String. valueOf (seekBar. getProgress ()));
}
@ Override
Public void onStartTrackingTouch (SeekBar seekBar ){
Log. d ("TAG", "start:" + String. valueOf (seekBar. getProgress ()));
}
@ Override
Public void onStopTrackingTouch (SeekBar seekBar ){
Log. d ("TAG", "stop:" + String. valueOf (seekBar. getProgress ()));
}
}
Excerpted from the column