• SeekBar


    SeekBar的使用很简单,和其他控件一样,先在布局文件中声明,然后在Activity中使用。

    下面演示下使用SeekBar改变图片的透明度:


    1.java文件

     1 package gdp.seekbartest;
     2 
     3 import android.annotation.SuppressLint;
     4 import android.app.Activity;
     5 import android.os.Bundle;
     6 import android.view.Menu;
     7 import android.widget.ImageView;
     8 import android.widget.SeekBar;
     9 import android.widget.SeekBar.OnSeekBarChangeListener;
    10 
    11 public class MianActivity extends Activity {
    12     private ImageView imageView ;
    13     private SeekBar seekBar ;
    14     @Override
    15     protected void onCreate(Bundle savedInstanceState) {
    16         super.onCreate(savedInstanceState);
    17         setContentView(R.layout.mian);
    18         
    19         imageView = (ImageView)findViewById(R.id.imageView);
    20         seekBar = (SeekBar)findViewById(R.id.seekBar);
    21         seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
    22             
    23             @Override
    24             public void onStopTrackingTouch(SeekBar arg0) {
    25                 // TODO Auto-generated method stub
    26                 
    27             }
    28             
    29             @Override
    30             public void onStartTrackingTouch(SeekBar arg0) {
    31                 // TODO Auto-generated method stub
    32                 
    33             }
    34             
    35             @SuppressLint("NewApi")
    36             @Override
    37             public void onProgressChanged(SeekBar arg0, int arg1, boolean arg2) {
    38                 // TODO Auto-generated method stub
    39                 imageView.setImageAlpha(arg1);
    40             }
    41         });
    42     }
    43 
    44     @Override
    45     public boolean onCreateOptionsMenu(Menu menu) {
    46         // Inflate the menu; this adds items to the action bar if it is present.
    47         getMenuInflater().inflate(R.menu.mian, menu);
    48         return true;
    49     }
    50 
    51 }

    2.xml文件

     1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     android:layout_width="fill_parent"
     3     android:layout_height="fill_parent"
     4     android:orientation="vertical" >
     5 
     6     <ImageView
     7         android:id="@+id/imageView"
     8         android:layout_width="match_parent"
     9         android:layout_height="wrap_content"
    10         android:src="@drawable/home" />
    11 
    12     <!-- 定义seekbar,并改变滑块外观 -->
    13 
    14     <SeekBar
    15         android:id="@+id/seekBar"
    16         android:layout_width="fill_parent"
    17         android:layout_height="wrap_content"
    18         android:max="255"
    19         android:progress="255"
    20         />
    21 </LinearLayout>
  • 相关阅读:
    重点词笔记
    pycharm tips
    标注精简过的问题如何导入问题库
    增加权重
    word2vec训练出来的相似词歧义
    算法测试及对比度进一步增强
    Python 命名笔记
    债务重组的会计处理方法
    实质性方案与综合性方案的区别
    什么叫认定层次
  • 原文地址:https://www.cnblogs.com/gdpdroid/p/3738790.html
Copyright © 2020-2023  润新知