Day17-进度条控件

.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;
	@Override
	protected 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);
	
	}
	
	@Override
	public 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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值