장면
효과
참고 :
블로그 :
https://blog.csdn.net/badao_liumang_qizhi
대한 대중의 우려 번호
원숭이 위압적 프로그램을
무료로 다운로드 인수 관련 프로그래밍 전자 책, 자습서 및 푸시.
실현
LinearLayout을 배치하고, 안드로이드 : 다음 방향 = "수직"> 수직 레이아웃 설정 및 이미지 뷰를 검색 막대를 추가하고, id 속성에 첨가 하였다.
투명성의 최대 값이 255 ~ 255 이후 상기 검색 막대는 최대 값이 추가
로이드 : 최대 = " 255 "
그리고, 설정 전류 값은 255
로이드 : 진행 = " 255 "
전체 XML 코드
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".SeekBarActivity" android:orientation="vertical"> <ImageView android:layout_width="match_parent" android:id="@+id/image" android:layout_height="250dp" android:src="@drawable/dog" /> <SeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/seekBar" android:max="255" android:progress="255" /> </LinearLayout>
然后来到Activity
分别通过id获取到ImageView和SeekBar
然后在seekBar的进度条改变事件中给imageView设置透明度。
package com.badao.relativelayouttest; import androidx.annotation.RequiresApi; import androidx.appcompat.app.AppCompatActivity; import android.os.Build; import android.os.Bundle; import android.widget.ImageView; import android.widget.SeekBar; public class SeekBarActivity extends AppCompatActivity { private SeekBar seekBar; private ImageView imageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_seek_bar); imageView = (ImageView) findViewById(R.id.image); seekBar = (SeekBar) findViewById(R.id.seekBar); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { imageView.setImageAlpha(progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); } }