本文主要是介绍ProgressBar --MarsChen Android 开发教程学习笔记,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.shumin.lbs05.MainActivity" >
<ProgressBar
android:id="@+id/thefirstbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:max="100"
style="@android:style/Widget.ProgressBar.Horizontal"
/>
<ProgressBar
android:id="@+id/thesecondbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thefirstbar"
style="@android:attr/progressBarStyleLarge"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/thesecondbar"
android:text="欧耶!"/>
</RelativeLayout>
package com.shumin.lbs05;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
public class MainActivity extends Activity {
private ProgressBar thefirstbar;
private ProgressBar thesecondbar;
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
thefirstbar=(ProgressBar)findViewById(R.id.thefirstbar);
thesecondbar=(ProgressBar)findViewById(R.id.thesecondbar);
button=(Button)findViewById(R.id.button);
thefirstbar.setMax(100);
thefirstbar.setProgress(5);
thefirstbar.setSecondaryProgress(10);
buttonListener listener=new buttonListener();
button.setOnClickListener(listener);
}
class buttonListener implements OnClickListener{
@Override
public void onClick(View v) {
thefirstbar.incrementProgressBy(5);
thefirstbar.incrementSecondaryProgressBy(5);
}
}
@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);
}
}
这篇关于ProgressBar --MarsChen Android 开发教程学习笔记的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!