2swan

Progressbar 본문

Programming/Android Example

Progressbar

2swan 2023. 8. 9. 16:51

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=".MainActivity2">

    <ProgressBar
        android:id="@+id/processBar1"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="100"
        android:progress="20"
        android:layout_marginTop="20dp"
        android:layout_marginBottom="20dp"/>
    <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"
        android:gravity="center"
        android:textSize="20sp"/>
    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

 

main.activity

public class MainActivity2 extends AppCompatActivity {

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

        ProgressBar progressBar = findViewById(R.id.processBar1);
        Button btnInc = findViewById(R.id.btnInc);
        Button btnDec = findViewById(R.id.btnDec);
        SeekBar seekBar = findViewById(R.id.seekBar1);
        TextView textView = findViewById(R.id.tvSeek);

        btnInc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                progressBar.incrementProgressBy(10);
            }
        });


        btnDec.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                progressBar.incrementProgressBy(-10);

            }
        });

        seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                textView.setText("진행률 : "+i + "%");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

    }
}

결과 값

'Programming > Android Example' 카테고리의 다른 글

Retrofit 예제  (0) 2023.08.09
음악 듣기 예제  (0) 2023.08.09
Tab 예제  (0) 2023.08.09
슬라이드 예제 2  (0) 2023.08.09
가로(세로) 슬라이드  (0) 2023.08.09