zoukankan      html  css  js  c++  java
  • 安卓学习-界面-ui-SeekBar

    和processbar差不多,只不过他的进度是可以拖动的,直接看效果

    activity_main.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="10dp" >
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="改变图片透明度"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
        <SeekBar
            android:id="@+id/seekBar1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:max="255"
            android:progress="255"
            android:thumb="@drawable/ic_launcher"
             />
    
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/pic1" />
    
    </LinearLayout>
    View Code

    MainActivity.java

    public class MainActivity extends Activity{
    
        SeekBar seekBar1;
        ImageView imageView1;
        
        Handler handler=new Handler(){
            public void handleMessage(Message msg) {
                if(msg.what==123){
                    int alpha =msg.getData().getInt("alpha");
                    imageView1.setImageAlpha(alpha);
                }
            }
        };
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            imageView1=(ImageView)findViewById(R.id.imageView1);
            seekBar1=(SeekBar)findViewById(R.id.seekBar1);
            seekBar1.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
                
                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    // TODO 自动生成的方法存根
                    
                }
                
                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                    // TODO 自动生成的方法存根
                    
                }
                
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress,
                        boolean fromUser) {
                    Message msg=new Message();
                    msg.what=123;
                    Bundle data=new Bundle();
                    data.putInt("alpha", progress);
                    msg.setData(data);
                    handler.sendMessage(msg);
                    
                }
            });
        }
    
    }
    View Code
  • 相关阅读:
    301重定向 修改默认网站访问文件
    修改本地host 文件 实现多“域名”访问 host'实现FQ
    thinkphp3.2.3 整合 富文本编辑器
    thinkphp3.2.3 跨数据库查询
    git 码云上关联仓库 克隆代码
    PHP GD库中输出图像乱码问题
    mysql 新建用户
    
    算法思想:
    算法思想:
  • 原文地址:https://www.cnblogs.com/weijj/p/3961369.html
Copyright © 2011-2022 走看看