又是一个安卓自带的方便控件,不用我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的要底层啊^_^