7

次の動作を示すフラグメント内にビューページャーがあります。ページ 2 以降は正しく表示されますが、最初のページはコンテナー ビューの背景の背後にあるかのように表示されます。つまり、背景よりも低い z-index があるかのように表示されます (z-index はユーザーに向かって増加します)。以下にリンクされている画像。

ページのインスタンス化のコードは次のとおりです。

pager.setAdapter(new PagerAdapter() {

    @Override
    public void destroyItem(ViewGroup container, int position, Object item) {
        container.removeView((View) item);
    }

    @Override
    public int getCount() {
        return mImages.size();
    }

    @Override
    public View instantiateItem(ViewGroup container, final int position) {
        LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View layout = inflater.inflate(R.layout.image_selector, null, false);

        final ImageView image = (ImageView) layout.findViewById(R.id.image);

        image.setImageResource(mImages.get(position));

        container.addView(layout);

        return layout;
    }

    @Override
    public boolean isViewFromObject(View view, Object item) {
        return item.equals(view)
    }

});

..特に特別なことはありません。

viewpager フラグメントのレイアウトは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="#ff2288dd">

  <TextView
    android:id="@+id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/help1" />

  <android.support.v4.view.ViewPager
    android:id="@+id/pager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/text1"
    android:layout_above="@+id/text2"
    android:layout_margin="12dip" />

  <TextView
    android:id="@id/text2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="@string/help2" />

</RelativeLayout>

ページごとの画像の場合:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true" />

</RelativeLayout>

繰り返しますが、異常なことは何もありません。

Froyo (2.2) と Gingerbread (2.3) の物理デバイスとエミュレータ、および 4.2 を実行している物理デバイスで動作が見られます。

奇妙な部分は、画像をタッチして選択すると、新しいフラグメントが元のビューページャーフラグメントを置き換え、選択された画像がビューページャーの最初のページからのものである場合、説明されている動作がそこにも存在することです-フラグメントが完全に異なるレイアウト (および背景が定義されていない新しいフラグメント)。

選択した画像フラグメントのレイアウト:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <ImageView
    android:id="@+id/image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true" />

</RelativeLayout>

以下参考画像。

先頭ページ

2ページ目に遷移

何が起こっているのか誰にも分かりませんか?

4

0 に答える 0