zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    codevs1288 埃及分数
    [BZOJ1697][Usaco2007 Feb]Cow Sorting牛排序
    [BZOJ1628][Usaco2007 Demo]City skyline
    [Usaco2005 Mar]Out of Hay 干草危机
    [Usaco2008 Open]Cow Neighborhoods 奶牛的邻居
    [BZOJ1691][Usaco2007 Dec]挑剔的美食家
    [BZOJ1668][Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富
    [BZOJ1593][Usaco2008 Feb]Hotel 旅馆
    [BZOJ1637][Usaco2007 Mar]Balanced Lineup
    [BZOJ1650][Usaco2006 Dec]River Hopscotch 跳石子
  • 原文地址:https://www.cnblogs.com/gdpdroid/p/3738790.html
Copyright © 2011-2022 走看看