android *** Layout 11 ProgressBar && RatingBar && SeekBar

ProgressBar是进度条,网站 http://android-doc.com/reference/android/widget/ProgressBar.html

xml代码

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:id="@+id/relative"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <ProgressBar
        android1:id="@+id/progressBar1"
        style="@android:style/Widget.ProgressBar.Inverse"
        android1:layout_width="wrap_content"
        android1:layout_height="wrap_content"
        android1:layout_alignParentTop="true"
        android1:layout_centerHorizontal="true"
        android1:layout_marginTop="54dp" />

    <Button
        android1:id="@+id/button1"
        android1:layout_width="wrap_content"
        android1:layout_height="wrap_content"
        android1:layout_below="@+id/progressBar1"
        android1:layout_centerHorizontal="true"
        android1:layout_marginTop="92dp"
        android1:text="Button" />

</RelativeLayout>

java代码如下

package com.example.tree;

import android.support.v7.app.ActionBarActivity;
import android.util.Log;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.*;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.AnalogClock;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;
import android.widget.Toast;


public class MainActivity extends ActionBarActivity implements OnClickListener{

	private Button button;
	private ProgressBar bar;
	private final String TAG="MainActivity";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Log.i(TAG, "-onCreate-->>");
		button=(Button)this.findViewById(R.id.button1);
		bar=(ProgressBar)this.findViewById(R.id.progressBar1);
		bar.setMax(100);//设置最大值100
		button.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				new MyTask().execute();
			}
			
		});
	}
	
	 class MyTask extends AsyncTask<Void,Integer,Void>{

		protected void OnProgressUpdate(Integer...values) {
			super.onProgressUpdate(values);
			bar.setProgress(values[0]);
			
		}

		@Override
		protected Void doInBackground(Void... params) {
			// TODO Auto-generated method stub
			int i=1;
			while(i<=100){
				try{
					Thread.sleep(500);
				}catch(Exception e){
					
				}
				publishProgress(i);
				i++;
			}
			return null;
		}

		
		
		
	}
	protected void onStart(){
		super.onStart();
		Log.i(TAG, "-onStart-->>");
	}
	
	protected void onRestart(){
		super.onRestart();
		Log.i(TAG, "-onRestart-->>");
	}
	
	protected void onResume(){
		super.onResume();
		Log.i(TAG, "-onResume-->>");
	}
	
	protected void onPause(){
		super.onPause();
		Log.i(TAG, "-onPause-->>");
	}
	
	protected void onStop(){
		super.onStop();
		Log.i(TAG, "-onStop-->>");
	}
	
	protected void onDestroy(){
		super.onDestroy();
		Log.i(TAG, "-onDestroy-->>");
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}
}


RatingBar是评分控件,SeekBar是类似于调音量的那种控件

java

package com.example.tree;

import android.support.v7.app.ActionBarActivity;
import android.util.Log;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.*;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.AnalogClock;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TimePicker;
import android.widget.TimePicker.OnTimeChangedListener;
import android.widget.Toast;


public class MainActivity extends ActionBarActivity implements OnClickListener{

	private Button button;
	private ProgressBar bar;
	private RatingBar rating;
	private SeekBar seek;
	private final String TAG="MainActivity";
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		Log.i(TAG, "-onCreate-->>");
		button=(Button)this.findViewById(R.id.button1);
		bar=(ProgressBar)this.findViewById(R.id.progressBar1);
		rating=(RatingBar)this.findViewById(R.id.ratingBar1);
		seek=(SeekBar)this.findViewById(R.id.seekBar1);
		bar.setMax(100);//设置最大值100
		button.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				new MyTask().execute();
			}
			
		});
		rating.setOnRatingBarChangeListener(new OnRatingBarChangeListener(){

			@Override
			public void onRatingChanged(RatingBar ratingBar, float rating, boolean fromUser) {
				// TODO Auto-generated method stub
				Log.i(TAG, "-->>"+rating);
			}
			
		});
		seek.setMax(100);
		seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener(){

			@Override
			public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
				// TODO Auto-generated method stub
				Log.i(TAG, "-->>"+progress);
			}

			@Override
			public void onStartTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onStopTrackingTouch(SeekBar seekBar) {
				// TODO Auto-generated method stub
				
			}
			
		});
	}
	
	 class MyTask extends AsyncTask<Void,Integer,Void>{

		protected void OnProgressUpdate(Integer...values) {
			super.onProgressUpdate(values);
			bar.setProgress(values[0]);
			
		}

		@Override
		protected Void doInBackground(Void... params) {
			// TODO Auto-generated method stub
			int i=1;
			while(i<=100){
				try{
					Thread.sleep(500);
				}catch(Exception e){
					
				}
				publishProgress(i);
				i++;
			}
			return null;
		}

		
		
		
	}
	protected void onStart(){
		super.onStart();
		Log.i(TAG, "-onStart-->>");
	}
	
	protected void onRestart(){
		super.onRestart();
		Log.i(TAG, "-onRestart-->>");
	}
	
	protected void onResume(){
		super.onResume();
		Log.i(TAG, "-onResume-->>");
	}
	
	protected void onPause(){
		super.onPause();
		Log.i(TAG, "-onPause-->>");
	}
	
	protected void onStop(){
		super.onStop();
		Log.i(TAG, "-onStop-->>");
	}
	
	protected void onDestroy(){
		super.onDestroy();
		Log.i(TAG, "-onDestroy-->>");
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		
	}
}


xml为

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android1="http://schemas.android.com/apk/res/android"
    android:id="@+id/relative"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="${relativePackage}.${activityClass}" >

    <ProgressBar
        android1:id="@+id/progressBar1"
        style="@android:style/Widget.ProgressBar.Inverse"
        android1:layout_width="wrap_content"
        android1:layout_height="wrap_content"
        android1:layout_alignParentTop="true"
        android1:layout_centerHorizontal="true"
        android1:layout_marginTop="54dp" />

    <RatingBar
        android1:id="@+id/ratingBar1"
        android1:layout_width="wrap_content"
        android1:layout_height="wrap_content"
        android1:layout_below="@+id/progressBar1"
        android1:layout_centerHorizontal="true"
        android1:layout_marginTop="18dp" />

    <Button
        android1:id="@+id/button1"
        android1:layout_width="wrap_content"
        android1:layout_height="wrap_content"
        android1:layout_alignParentBottom="true"
        android1:layout_centerHorizontal="true"
        android1:layout_marginBottom="102dp"
        android1:text="Button" />

    <SeekBar
        android1:id="@+id/seekBar1"
        android1:layout_width="match_parent"
        android1:layout_height="wrap_content"
        android1:layout_alignParentLeft="true"
        android1:layout_centerVertical="true" />

</RelativeLayout>


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值