有没有可能在Android中构建一个像HTML 5中存在的图像比较滑块控件一样的东西?
如何实现这个功能?请参考以下链接:http://thenewcode.com/819/A-Before-And-After-Image-Comparison-Slide-Control-in-HTML5
如何实现这个功能?请参考以下链接:http://thenewcode.com/819/A-Before-And-After-Image-Comparison-Slide-Control-in-HTML5
compile 'com.github.developer--:beforeafterslider:1.0.4'
一种方法是使用一个 seekbar 和一个 framelayout,它位于原始图像之上。当您滑动 seekbar 时,包含第二张图片的帧高度会调整。
从上到下揭示的代码
private SeekBar seekBar;
protected void onCreate(Bundle savedInstanceState) {
下方添加:seekBar = (SeekBar) findViewById(R.id.seekBar1);
seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
int progress = 0;
@Override
public void onProgressChanged(SeekBar seekBar, int progresValue, boolean fromUser) {
FrameLayout target = (FrameLayout) findViewById(R.id.target);
progress = progresValue;
ViewGroup.LayoutParams lp = target.getLayoutParams();
lp.height = progress;
target.setLayoutParams(lp);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_main" tools:context=".MainActivity">
<ImageView
android:id="@+id/image"
android:layout_width="600dp"
android:layout_height="300dp"
android:src="@drawable/pug_color"/>
<FrameLayout
android:id="@+id/target"
android:layout_width="600dp"
android:layout_height="150dp">
<ImageView
android:id="@+id/imageb"
android:layout_width="600dp"
android:layout_height="300dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/pug_bw"/>
</FrameLayout>
<SeekBar
android:id="@+id/seekBar1"
android:layout_below="@+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:progress="300"
android:max="600" />
</RelativeLayout>
drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)
方法相应地绘制它们。 - tato.rodrigo