Android控件-进度条

本文详细介绍了Android中的三种进度条组件:ProgressBar、SeekBar和RatingBar,包括它们的属性设置和事件监听。同时提到了如何操作assets文件夹以及实现页面跳转。强调了主线程(UI线程)只能更新UI,并提供了相关代码示例。
摘要由CSDN通过智能技术生成

ProgressBar

属性:style:“?android:attr/peogressBarStyleHorizontal” //设置样式(圈大 圈小 水平样式)
progress:20 //当前进度
max:100 //最大进度
min:0 //最小进度

SeekBar

属性:同上
事件:onSeekBarChangeLinsener //三个方法:1.进度改变 带参数progress 2.开始拖拉 3.停止拖拉

RatingBar

属性:android:numStarts = “5” //星星数量
android:min = “0”;
android:rating = “0.3” //当前进度
android:stepSize = “0.5” //步数(一颗星几次点完)

assets

方法:getAssets(); //获得assets文件夹
open(文件名) //打开指定文件 得到inputStream对象

页面跳转

Intent intent = new Intent(LoadFileActivity.this,Main)

注意事项

主线程又叫UI线程只能更新UI
runonUiThread(线程1对象) //将线程1发送到主线程执行

代码实现

// An highlighted block
<LinearLayout
        android:id="@+id/activity04"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="5"
        android:orientation="vertical"
        android:visibility="gone">

        <TextView
            android:id="@+id/dq"
            android:layout_width="match_parent"
            android:layout_height="200dp" />

        <ProgressBar
            android:id="@+id/jdt"
            android:layout_width="match_parent"
            android:layout_height="40dp"
            style="?android:attr/progressBarStyleHorizontal"
            android:max="742" />

        <Button
            android:id="@+id/ksxz"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:text="开始下载"/>

    </LinearLayout>






//JAVA代码

package com.example.tx.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class allActivity extends AppCompatActivity {
   

    Button btn1;
    Button btn2;
    Button btn3;
    Button btn4;
    Button btn5;

    LinearLayout linearLayout1;
    LinearLayout linearLayout2;
    LinearLayout linearLayout3;
    LinearLayout linearLayout4;

    TextView text1;

    ImageView imageView1;

    RadioButton radioButton1;
    RadioButton radioButton2;
    RadioButton radioButton3;
    RadioButton radioButton4;

    TextView textView01;
    TextView textView02;
    TextView textView03;
    TextView textView04;
    TextView textView05;
    TextView textView06;


    ImageView yejian;
    ImageView qiandao;
    ImageView touxiang;

    Button begin;
    TextView wenbenyu;
    ProgressBar jindutiao;
    StringBuffer stringBuffer = new StringBuffer();

    int sum = 0;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
   
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all);

        wenbenyu = findViewById(R.id.dq);
        jindutiao = findViewById(R.id.jdt);

        linearLayout1 = findViewById(<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值