標籤:
又是一個安卓內建的方便控制項,不用我html/css/js自己寫了。
用可視化面板拖進去以後
<RelativeLayout 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" 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="com.narumi.android_13_1.MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <SeekBar android:id="@+id/seekBar1" android:layout_width="match_parent" android:layout_height="50dp" android:layout_alignParentLeft="true" android:layout_below="@+id/textView1" android:layout_marginTop="93dp" /> <ProgressBar android:id="@+id/progressBar1" style="?android:attr/progressBarStyleHorizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginTop="29dp" android:maxWidth="200dp" /></RelativeLayout>
java裡面擷取一下控制項對象,綁定事件,這裡使得第一個bar跟隨後面的seekbar改進度
package com.narumi.android_13_1;import android.app.Activity;import android.os.Bundle;import android.widget.ProgressBar;import android.widget.SeekBar;import android.widget.SeekBar.OnSeekBarChangeListener;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //final才能使子方法的代碼塊訪問得到 final SeekBar skb = (SeekBar)findViewById(R.id.seekBar1); final ProgressBar pb = (ProgressBar)findViewById(R.id.progressBar1); skb.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub pb.setProgress(skb.getProgress()); } }); } }
這樣看來做js的比做java的要底層啊^_^
安卓天天練練(十二)進度條