2014年11月23日 星期日

Android開發零點起飛(第四章)筆記-ProgressBar範例改寫(4-1)

Android開發零點起飛(第四章)筆記-ProgressBar範例改寫(4-1)


 


建立ProgressBar*3,ProgressBar元件實作(利用LinearLayout.LayoutParams放大元件)


 


 


package com.jashsample;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URI;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Random;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;

import android.media.MediaPlayer;
import android.media.MediaPlayer.OnCompletionListener;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.ContactsContract;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.app.SearchManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Camera;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.hardware.Camera.Size;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.speech.RecognizerIntent;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.text.format.DateFormat;
import android.text.method.KeyListener;
import android.view.Display;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.Surface;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.widget.ViewFlipper;
/*
 * 建立ProgressBar*4,ProgressBar元件實作。
 */
/*
 * <uses-permission android:name="android.permission.INTERNET" />
 */
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
setContentView(ll);
ProgressBar progressBar1= new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);//style="?android:attr/progressBarStyleHorizontal"
progressBar1.setMax(100);//android:max="100"
progressBar1.setProgress(75);//android:progress="75"
progressBar1.setSecondaryProgress(50);//android:secondaryProgress="50"
ll.addView(progressBar1);
ProgressBar progressBar2=new ProgressBar(this, null, android.R.attr.progressBarStyleSmall);//style="?android:attr/progressBarStyleSmall"
ll.addView(progressBar2);

ProgressBar progressBar3=new ProgressBar(this, null, android.R.attr.progressBarStyleLarge);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(300, 300);//用LinearLayout.LayoutParams放大元件
//RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(500,500);
//params.addRule(RelativeLayout.CENTER_IN_PARENT);
progressBar3.setLayoutParams(params);
ll.addView(progressBar3);

ProgressBar progressBar4=new ProgressBar(this, null, android.R.attr.progressBarStyleLarge);
ll.addView(progressBar4);
//ll.addView(tb);
}

}


















 






沒有留言:

張貼留言