zoukankan      html  css  js  c++  java
  • 控件:拖动条 SeekBar(图片浏览)

               

    View Code
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation
    ="vertical"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="fill_parent">
    <ImageView
    android:id="@+id/pic"
    android:src
    ="@drawable/pic_0"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content"/>
    <SeekBar
    android:id="@+id/seekbar"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content" />
    </LinearLayout>
    View Code
    import android.app.Activity;
    import android.os.Bundle;
    import android.text.method.ScrollingMovementMethod;
    import android.widget.ImageView;
    import android.widget.SeekBar;
    import android.widget.TextView;

    public class MySeekBarDemo extends Activity {
    private SeekBar seekbar = null;
    private ImageView pic = null;
    private int picData[] = new int[] {
    R.drawable.pic_0, R.drawable.pic_1,
    R.drawable.pic_2, R.drawable.pic_3, R.drawable.pic_4,
    R.drawable.pic_5, R.drawable.pic_6, R.drawable.pic_7,
    R.drawable.pic_8, R.drawable.pic_9 };

    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    super.setContentView(R.layout.main);
    // 取得组件
    this.seekbar = (SeekBar) super.findViewById(R.id.seekbar);
    // 取得组件
    this.pic = (ImageView) super.findViewById(R.id.pic);
    // 0 ~ 9的范围
    this.seekbar.setMax(9);
    this.seekbar.setOnSeekBarChangeListener(new OnSeekBarChangeListenerImpl());
    }

    private class OnSeekBarChangeListenerImpl implements SeekBar.OnSeekBarChangeListener {
    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
    }
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {
    // 设置显示图片
    MySeekBarDemo.this.pic
    .setImageResource(MySeekBarDemo.this.picData[seekBar
    .getProgress()]);
    }
    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
    }

    }
    }



  • 相关阅读:
    apt-get connects to web
    Particle Filter(CC) 放狗
    Get a specific pixel coordinates where your mouse on (cc)
    event
    两张图片的平移实验 (SLAM translate epipolar geometry)
    vs2010 LINK : fatal error LNK1123: 转换到 COFF 期间失败:(cc)
    fx and fy in Calibration
    How do I get add-apt-repository to work through a proxy?
    ROS and PCL install
    Longest palindrome subsequence
  • 原文地址:https://www.cnblogs.com/androidsj/p/2379156.html
Copyright © 2011-2022 走看看