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) {
    }

    }
    }



  • 相关阅读:
    Tampermonkey 油猴脚本开发 入门
    k8s 上安装 lamp 环境
    centOS 7.9 k8s 安装 和 基本命令
    力扣59-螺旋矩阵 II
    力扣54-螺旋矩阵
    力扣705-设计哈希集合
    力扣706-设计哈希映射
    scrapy参数-COOKIES_ENABLED
    优雅降级、渐进增强
    e-cahr的地图组件封装(浙江省为例)
  • 原文地址:https://www.cnblogs.com/androidsj/p/2379156.html
Copyright © 2011-2022 走看看