我使用ViewPager进行以下布局,基本上可以循环浏览各种图像。
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="@+id/imagePager_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<PhotoView
android:id="@+id/imagePager_imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/imagePager_textTitle"
android:layout_width="fill_parent"
android:gravity="center"
android:textStyle="bold"
android:text="TITLE"
android:layout_margin="0dp"
android:layout_below="@+id/imagePager_imageView"
android:layout_height="wrap_content"/>
<ImageView android:id="@+id/imagePager_titleLine"
android:layout_width="fill_parent"
android:layout_below="@+id/imagePager_textTitle"
android:layout_height="match_parent"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="@drawable/linebig"/>
<TextView
android:id="@+id/imagePager_textSubtitle"
android:layout_width="fill_parent"
android:gravity="center"
android:text="SUBTITLE"
android:layout_margin="0dp"
android:layout_below="@+id/imagePager_titleLine"
android:layout_height="wrap_content"/>
<ImageView android:id="@+id/imagePager_subtitleLine"
android:layout_below="@+id/imagePager_textSubtitle"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:paddingBottom="10dp"
android:src="@drawable/linebig"/>
<TextView
android:id="@+id/imagePager_textContent"
android:layout_width="fill_parent"
android:paddingTop="15dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="CONTENT"
android:layout_margin="0dp"
android:layout_below="@+id/imagePager_subtitleLine"
android:layout_height="wrap_content"/>
</RelativeLayout>
</ScrollView>
从图片下方的图片中我可以看到一些描述的视图。我想要实现的目标如下。
我的ImageAdapter如下(仅包括相关方法):
@Override
public Object instantiateItem(ViewGroup container, int position) {
View layout = null;
if (container.getContext() != null) {
//load imagepager layout
LayoutInflater inflater = (LayoutInflater) container.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = inflater.inflate(R.layout.image_pager, container, false);
if (layout != null) {
//Fill in textviews
//get current bitmap depending on viewpager position
//Bitmap is saved as byte[] in container
int imageNumber = getImageNumber(position);
BitmapContainer bitmap = getBitmap(imageNumber);
//create imageview
setImageview(layout, bitmap);
container.addView(layout, ActionBar.LayoutParams.FILL_PARENT,
ActionBar.LayoutParams.FILL_PARENT);
}
}
return layout;
}
private void setImageview(View layout, BitmapContainer container) {
PhotoView iv = (PhotoView) layout.findViewById(R.id.imagePager_imageView);
iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
Bitmap bitmap = BitmapFactory.decodeByteArray(container.getImage(), 0,
container.getImage().length);
iv.setImageBitmap(bitmap);
}
}
问题是位图还没有调整它的imageview,下面的文本视图仍然保持不变。