基本的に、私はこの質問を再質問していますが、アンドロイドに実装するためです。
ユーザーが静止画像のフィルター間をスワイプできるようにしようとしています。アイデアは、フィルターがその上をスクロールしている間、画像が所定の位置に留まるということです。Snapchat は最近、この機能を実装したバージョンをリリースしました。このビデオの 1:05 で、私が達成しようとしていることを正確に示しています。
リストをオーバーレイで埋めて、onFling でページングし、onDraw で描画しようとしましたが、アニメーションが失われます。ViewPager でこれを行う方法はありますか?
編集: 要求に応じて、オーバーレイ ビュー ページングの実装を提供しました。画像ビューの上にある透明なpng画像でviewpagerを埋めます。また、Xamarin Android を使用しているため、このコードは C# です。C# に慣れていない人にとっては、Java にかなり似ています。
...
static List<ImageView> overlayList = new List<ImageView>();
...
public class OverlayFragmentAdapter : FragmentPagerAdapter
{
public OverlayFragmentAdapter(Android.Support.V4.App.FragmentManager fm) : base(fm)
{
}
public override int Count
{
get { return 5; } //hardcoded temporarily
}
public override Android.Support.V4.App.Fragment GetItem(int position)
{
return new OverlayFragment ();
}
}
public class OverlayFragment : Android.Support.V4.App.Fragment
{
public override View OnCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.Inflate (Resource.Layout.fragment_overlay, container, false);
LinearLayout l1 = view.FindViewById<LinearLayout> (Resource.Id.overlay_container);
ImageView im = new ImageView (Activity);
im.SetImageResource (Resource.Drawable.Overlay); //Resource.Drawable.Overlay is a simple png transparency I created. R
l1.AddView (im);
overlayList.AddElement (im);
return view;
}
}
アクティビティ レイアウト XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom">
<ImageView
android:id="@+id/background_image"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<RelativeLayout <!-- This second layout is for buttons which I have omitted from this code -->
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/edit_layout">
<android.support.v4.view.ViewPager
android:id="@+id/overlay_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</RelativeLayout>
フラグメント オーバーレイ XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/overlay_container"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" />
簡単に要約すると、viewpager は背景として機能する最初の imageview の上に置かれます。OnCreateView メソッドは、リソースからオーバーレイ フラグメントとオーバーレイ イメージビューを作成し、overlay_container レイアウト内に配置します。画像の保存(この質問の範囲外であるため投稿していません)は簡単です。背景ビットマップ、オーバーレイビットマップを作成し、キャンバスを使用してオーバーレイを背景に描画し、次に書き込みますファイル。