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;
    }

}

 

posted @ 2013-09-02 17:07  狂吼的面包圈  阅读(476)  评论(0编辑  收藏  举报