zoukankan      html  css  js  c++  java
  • android实例3:拖动条

    个人网站http://www.ravedonut.com/

    拖动条改变图片的透明度

    xml

    <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/image"
            android:layout_width="fill_parent"
            android:layout_height="240px"
            android:src="@drawable/logo"
            />
        
        <SeekBar 
            android:id="@+id/seelbar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:max="255"
            android:progress="255"
            android:thumb="@drawable/ic_launcher"
            />
         
    </LinearLayout>

    资源方面,SeeKBar的thumb时拖动条按钮的样式,

    activity:

    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.widget.ImageView;
    import android.widget.SeekBar;
    
    public class MainActivity extends Activity {
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            
            final ImageView image =(ImageView)findViewById(R.id.image);
            SeekBar seekbar = (SeekBar)findViewById(R.id.seelbar);
            
            seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                
                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                    // TODO Auto-generated method stub
                    
                }
                
                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                    // TODO Auto-generated method stub
                    
                }
                
                @Override
                public void onProgressChanged(SeekBar seekBar, int progress,
                        boolean fromUser) {
                    // TODO Auto-generated method stub
                    image.setAlpha(progress);
                }
            });
            
            
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
    }
  • 相关阅读:
    variables _ golang
    values _ golang
    hello world _ golang
    golang
    英语
    ubuntu下安装node、node代码调试
    xampp日常需求
    垂直居中方法总结
    angularJS之ui-router插件(1)
    Sass学习
  • 原文地址:https://www.cnblogs.com/panjiangfy/p/android3.html
Copyright © 2011-2022 走看看