Day17-进度条控件

来源:互联网 发布:java jdk 编辑:程序博客网 时间:2024/06/07 01:45

.java代码:

package com.example.day1;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.ProgressBar;public class progress extends Activity implements OnClickListener{private Button one;private Button two;private ProgressBar progress;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.progress);one=(Button) findViewById(R.id.one);    two=(Button) findViewById(R.id.two);    progress=(ProgressBar) findViewById(R.id.progress);    //点击事件    one.setOnClickListener(this);    two.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()) {case R.id.one:int currentprogress1=progress.getProgress();  // 获取当前进度值int prog1=(int) (currentprogress1*1.2); // 设置增加的进度值progress.setProgress(prog1);break;case R.id.two:int currentprogress2=progress.getProgress();int prog2=(int) (currentprogress2*0.5);progress.setProgress(prog2);   // 设置减少的进度值break;}}}


.xml代码:

<?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"     >        <ProgressBar         android:layout_width="wrap_content"        android:layout_height="wrap_content"        style="?android:attr/progressBarStyleSmall"        />    <ProgressBar        android:layout_width="wrap_content"        android:layout_height="wrap_content"        style="?android:attr/progressBarStyleLarge"/>        <ProgressBar           android:id="@+id/progress"        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:progress="30"        android:layout_marginTop="50dip"        style="?android:attr/progressBarStyleHorizontal"/>        <LinearLayout        android:layout_width="wrap_content"        android:layout_height="wrap_content">              <Button           android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:id="@+id/one"          android:text="增加"/>                  <Button           android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:id="@+id/two"          android:text="减少"/>      </LinearLayout>    </LinearLayout>



0 0
原创粉丝点击