UI:使View背景逐渐变暗的方法

来源:互联网 发布:redis php扩展 编辑:程序博客网 时间:2024/06/11 02:11

使用View 的 setAlpha(int alpha);

代码

setContentView(R.layout.activity_alpha_view);SeekBar seekBar = (SeekBar) findViewById(R.id.seekbar);seekBar.setMax(100);final LinearLayout ll = (LinearLayout) findViewById(R.id.rl);seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {}@Overridepublic void onProgressChanged(SeekBar seekBar, int progress,boolean fromUser) {ll.setAlpha(progress * 1.0f / 100);}});

xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"     android:background="#333333">        <SeekBar         android:id="@+id/seekbar"        android:layout_width="match_parent"        android:layout_height="wrap_content"/>        <LinearLayout         android:id="@+id/rl"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:orientation="vertical"        android:background="#f0f0f0">    </LinearLayout></LinearLayout>


其实就是将当前view 的透明度放低, 从而显示出ViewGroup的背景颜色

 

0 0
原创粉丝点击