activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="?android:attr/progressBarStyleHorizontal"
android:max="100"
android:progress="20"/>
<Button
android:id="@+id/btnInc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="10씩 증가"/>
<Button
android:id="@+id/btnDec"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="10씩 감소"/>
<TextView
android:id="@+id/tvSeek"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<SeekBar
android:id="@+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
MainActivity.java
package com.example.progressseekbar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.SeekBar;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ProgressBar pb1;
Button btnInc, btnDec;
pb1 = (ProgressBar) findViewById(R.id.progressBar1);
btnInc = (Button) findViewById(R.id.btnInc);
btnDec = (Button) findViewById(R.id.btnDec);
btnInc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pb1.incrementProgressBy(10);
}
});
btnDec.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pb1.incrementProgressBy(-10);
}
});
final TextView tvSeek = (TextView) findViewById(R.id.tvSeek);
SeekBar seekBar1 = (SeekBar) findViewById(R.id.seekBar1);
seekBar1.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
//progress(원 모양)를 터치해서 좌우로 끌면 이동한 값을 출력
tvSeek.setText("진행률 : "+progress+" %");
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
}
}
실행 화면
'안드로이드 > 연습' 카테고리의 다른 글
[Android] Thread (0) | 2021.08.29 |
---|---|
[Android] 간단 MP3 플레이어 만들기 (0) | 2021.08.29 |
[Android] 가수 그룹 관리 DB 만들기 (0) | 2021.08.29 |
[Android] 영화 포스터 보기(GridLayout) (0) | 2021.08.27 |
[Android] ListView (0) | 2021.08.27 |