Android Viewpager背景色在第一页中溢出
我在一个片段中有一个viewpager,它显示了以下行为。第2页以后的页面显示正确,但第一页显示时好像它位于容器视图的背景后面—好像它的z索引比背景低(其中z索引向用户方向增加)—请参阅下面链接的图像 页面实例化的代码是:Android Viewpager背景色在第一页中溢出,android,background,android-viewpager,fragment,Android,Background,Android Viewpager,Fragment,我在一个片段中有一个viewpager,它显示了以下行为。第2页以后的页面显示正确,但第一页显示时好像它位于容器视图的背景后面—好像它的z索引比背景低(其中z索引向用户方向增加)—请参阅下面链接的图像 页面实例化的代码是: pager.setAdapter(new PagerAdapter() { @Override public void destroyItem(ViewGroup container, int position, Object item) {
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>
有人知道会发生什么吗 你有没有想过这个问题?我想这和我看到的东西很相似。后来我又转到了其他项目,但如果你使用的是最新版本的Android,看到这个问题可能仍然存在会有点令人沮丧。这只发生在4.2及以下版本的我身上。我不是100%确定这是否是个问题,但听起来很像。我也继续前进。
<?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>
<?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>