
<!--
android:src="" 指定前景图片资源
android:background="" 设置背景
android:layout_width="wrap_content" 是根据图片比例正常显示
android:layout_height="wrap_content"
-->
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/add_photo" />

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context=".ProgressBarActivity"
android:orientation="vertical"
android:background="#ff0000">
<!--
进度条:默认样式是转圈。修改样式需设置风格
style 设置风格progressBarStyleHorizontal(水平进度条)
android:progress="" 设置进度
android:max="" 设置最大值,默认100
android:indeterminate="true" 设置进度条一直滚动
-->
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:progress="30"
android:max="200"/>
<ProgressBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:indeterminate="true"/>
<ProgressBar
android:id="@+id/progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"/>
</LinearLayout>
package com.example.uidemo;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ProgressBar;
public class ProgressBarActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_progress_bar);
final ProgressBar progressBar = findViewById(R.id.progress);
progressBar.setProgress(80);
//在Android中,4.0以后是不能直接在线程中操作控件的
//进度条是个特例
new Thread(){
@Override
public void run() {
for(int i = 1 ; i <= 100 ; i++) {
progressBar.setProgress(i);
try {
Thread.sleep(30);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}.start();
}
}
SeekBar
image.png
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.SeekBar;
public class BaseUiActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_base_ui);
CheckBox checkboxBtn = findViewById(R.id.checkboxBtn);
checkboxBtn.setChecked(false);
// 判断是否选中
boolean isCheckbox = checkboxBtn.isChecked();
Log.e("TAG","isCheckbox"+isCheckbox);
// 监听 check状态改变的时候,可以处理其他事情
checkboxBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.e("TAG","当前改变的状态"+isChecked);
}
});
SeekBar seekBar = findViewById(R.id.seekBar);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
Log.e("TAG","progress改变的 : "+progress);
}
// 开始的时候
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
// 结束的时候
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
}
网友评论