진도
26781 단어 진도 표
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/progressbar1" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressbar1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/progressbar2" />
<!-- : , , style="?android:attr/progressBarStyleHorizontal-->
<ProgressBar
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/progressbar2"
/>
</LinearLayout>
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
자바 프로그램
package com.example.progressbardemo;
import java.security.PublicKey;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.view.Menu;
import android.widget.ProgressBar;
public class MainActivity extends Activity {
private ProgressBar mProgressBar;
private int mProgressStatus = 0;
// Handler
private Handler mHandler = new Handler();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mProgressBar = (ProgressBar) findViewById(R.id.progressbar2);
// ,
mProgressBar.setMax(1000);
//
new Thread( new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
// 1000 , mprogresstatus
while(mProgressStatus++<1000)
{
// runnable , run
mHandler.post(new Runnable() { //
@Override
public void run() {
// TODO Auto-generated method stub
//
mProgressBar.setProgress(mProgressStatus);
}
});
}
}
}).start();
}
@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;
}
}
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
드래그 바(SeekBar)
seekbar 는 Progressbar 의 하위 클래스 입 니 다.
몇 가지 방법 이 있 습 니 다.
SeekBar.getProgress()드래그 바 현재 값 가 져 오기
setOnSeekBarChangeListener()방법,드래그 바 값 변화 이 벤트 를 처리 하고 SeekBar.OnSeekBarChangeListener 인 스 턴 스 를 매개 변수 로 전송 합 니 다.
string.xml 파일
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name"> </string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="speed"> </string>
</resources>
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
main.xml 파일
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/speed"
android:id="@+id/speed"
/>
<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/seek_bar"
/>
</LinearLayout>
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
activity.java 파일
1: package com.example.seekbardemo;
2:
3: import android.R.bool;
4: import android.os.Bundle;
5: import android.os.Handler;
6: import android.app.Activity;
7: import android.view.Menu;
8: import android.widget.SeekBar;
9: import android.widget.TextView;
10:
11: public class MainActivity extends Activity {
12: private SeekBar seekBar;
13: private TextView textView;
14: //
15: private boolean flag = true;
16: private Handler handler = new Handler();
17:
18: @Override
19: protected void onCreate(Bundle savedInstanceState) {
20: super.onCreate(savedInstanceState);
21: setContentView(R.layout.activity_main);
22:
23: seekBar = (SeekBar) findViewById(R.id.seek_bar);
24: textView = (TextView) findViewById(R.id.speed);
25:
26: // , 。
27: seekBar.setMax(100);
28: // seekBar , SeekBar l 。
29: seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
30:
31: @Override
32: public void onStopTrackingTouch(SeekBar seekBar) {
33: // TODO Auto-generated method stub
34: //
35: flag = true;
36: refrech();
37:
38: }
39:
40: @Override
41: public void onStartTrackingTouch(SeekBar seekBar) {
42: // TODO Auto-generated method stub
43: flag = false;
44: }
45:
46: @Override
47: public void onProgressChanged(SeekBar seekBar, int progress,
48: boolean fromUser) {
49: // TODO Auto-generated method stub
50: // textView
51: textView.setText(" : " + progress + "%");
52: }
53: });
54:
55:
56: }
57:
58: protected void refrech() {
59: // TODO Auto-generated method stub
60: new Thread(new Runnable() {
61:
62: @Override
63: public void run() {
64: // TODO Auto-generated method stub
65: while(flag && seekBar.getProgress()<100)
66: {
67: try{
68: //
69: Thread.sleep(1000);
70: }
71: catch (Exception e)
72: {
73: // TODO: handle exception
74: e.printStackTrace();
75: }
76: // Runnable ,
77: // run()
78: handler.post(new Runnable() {
79: public void run() {
80: // , 1
81: seekBar.setProgress(seekBar.getProgress() + 1);
82: }
83: });
84:
85: }
86: }
87: }).start();
88: }
89:
90: @Override
91: public boolean onCreateOptionsMenu(Menu menu) {
92: // Inflate the menu; this adds items to the action bar if it is present.
93: getMenuInflater().inflate(R.menu.main, menu);
94: return true;
95: }
96:
97: }
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
설명:SeekBarActivity 가 생 성 되 었 을 때 seekBar 에 감청 이 벤트 를 등록 합 니 다.또한 refresh()방법 을 호출 하여 드래그 바 의 진도 값 을 자동 으로 새로 고 칩 니 다.드래그 바 의 진도 값 이 바 뀌 었 을 때 seekBar 상부 TextView 의 내용 을 수정 합 니 다.