본문 바로가기

Android

프로그레스 바 (ProgressBar) 실습

Activity_main.xml

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:id="@+id/LinearLayout1"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".MainActivity" >

 

    <ProgressBar

        android:id="@+id/progressbar"

        style="?android:attr/progressBarStyleHorizontal"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:max="100"

        android:progress="10"

        android:secondaryProgress="50" />

 

    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="horizontal" >

 

        <Button

            android:id="@+id/btn1"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="첫번째 막대 증가" />

 

        <Button

            android:id="@+id/btn2"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="두번째 막대 증가" />

    </LinearLayout>

 

     <!-- 기본적으로 안보이게 설정해놓는다. -->

    <ProgressBar

        android:id="@+id/progresscircle"

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:visibility="invisible" />

   

      <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="horizontal" >

 

        <Button

            android:id="@+id/btn3"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="진행바 보이기" />

 

        <Button

            android:id="@+id/btn4"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="진행바 안보이기" />

    </LinearLayout>

 

</LinearLayout>

 

 

MainActivity.java

 

package com.example.progressbarex01;

 

import android.app.Activity;

import android.os.Bundle;

import android.view.Menu;

import android.view.View;

import android.widget.ProgressBar;

 

public class MainActivity extends Activity {

     ProgressBar progressBar;

     ProgressBar progressCircle;

    

     @Override

     protected void onCreate(Bundle savedInstanceState) {

           super.onCreate(savedInstanceState);

           setContentView(R.layout.activity_main);

          

           progressBar = (ProgressBar)findViewById(R.id.progressbar);

           progressCircle = (ProgressBar)findViewById(R.id.progresscircle);

          

           findViewById(R.id.btn1).setOnClickListener(clickListener);

           findViewById(R.id.btn2).setOnClickListener(clickListener);

           findViewById(R.id.btn3).setOnClickListener(clickListener);

           findViewById(R.id.btn4).setOnClickListener(clickListener);

     }

    

     private View.OnClickListener clickListener = new View.OnClickListener() {

          

           @Override

           public void onClick(View v) {

                // TODO Auto-generated method stub

                if(v.getId()==R.id.btn1){

                     progressBar.incrementProgressBy(5);

                } else if(v.getId()==R.id.btn2){

                     progressBar.incrementSecondaryProgressBy(5);

                } else if(v.getId()==R.id.btn3){

                     progressCircle.setVisibility(View.VISIBLE);

                } else if(v.getId()==R.id.btn4){

                     progressCircle.setVisibility(View.INVISIBLE);

                }

           }

     };

 

     @Override

     public boolean onCreateOptionsMenu(Menu menu) {

           // Inflate the menu; this adds items to the action bar if it is present.

           getMenuInflater().inflate(R.menu.main, menu);

           return true;

     }

 }




 

'Android' 카테고리의 다른 글

시크바(SeekBar)  (0) 2013.04.02
프로그레스 바 (ProgressBar) 실습2  (0) 2013.04.02
어댑터뷰 - 갤러리  (0) 2013.04.01
어댑터뷰 - 그리드  (0) 2013.04.01
어댑터 뷰 - 스피너  (0) 2013.04.01