您的位置:首页 > 产品设计 > UI/UE

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

2015-10-12 15:58 267 查看
使用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() {

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}

@Override
public 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的背景颜色

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: