gpt4 book ai didi

java - ImageView 填充空白 ViewPager Android

转载 作者:行者123 更新时间:2023-11-29 20:23:50 25 4
gpt4 key购买 nike

我一直在学习本教程 Image Slide Using View Pager但我无法使图像 View inside view pager 在水平和垂直方向上填充 view pager 内的完整空间。知道如何做到这一点吗?

我已经在我的页面适配器中尝试过这个

mImageView.setAdjustViewBounds(true);
mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);

但仍然没有运气:(

我的布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="2dp"
tools:context=".MainActivity" >

<RelativeLayout
android:id="@+id/img_slideshow_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="@drawable/img_border" >

<android.support.v4.view.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="150dp" />

<TextView
android:id="@+id/img_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/indicator"
android:background="#88343434"
android:ellipsize="end"
android:paddingBottom="2dp"
android:paddingLeft="5dp"
android:paddingRight="2dp"
android:paddingTop="2dp"
android:singleLine="true"
android:textColor="#ededed" />

<apps.modisku.com.modisku.helper.CirclePageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/view_pager"
android:padding="10dip" />
</RelativeLayout>

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

<ImageView
android:id="@+id/image_display"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/txt_image_slider" />

</RelativeLayout>

我的 PageAdapter

public class ImageSlideAdapter extends PagerAdapter {
ImageLoader imageLoader = ImageLoader.getInstance();
DisplayImageOptions options;
private ImageLoadingListener imageListener;
FragmentActivity activity;
List<Product> products;
HomeFragment homeFragment;

public ImageSlideAdapter(FragmentActivity activity, List<Product> products,
HomeFragment homeFragment) {
this.activity = activity;
this.homeFragment = homeFragment;
this.products = products;
options = new DisplayImageOptions.Builder()
.showImageOnFail(R.drawable.ic_error)
.showStubImage(R.drawable.ic_launcher)
.showImageForEmptyUri(R.drawable.ic_empty).cacheInMemory()
.cacheOnDisc().showImageOnLoading(R.drawable.loadingicontransprant).build();

imageListener = new ImageDisplayListener();
}

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

@Override
public View instantiateItem(ViewGroup container, final int position) {
LayoutInflater inflater = (LayoutInflater) activity
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.vp_image, container, false);

ImageView mImageView = (ImageView) view
.findViewById(R.id.image_display);


// mImageView.setLayoutParams(new ViewGroup.LayoutParams(mScreenWidth, ViewGroup.LayoutParams.WRAP_CONTENT));
mImageView.setAdjustViewBounds(true);
mImageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
mImageView.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Bundle arguments = new Bundle();
Fragment fragment = null;
Log.d("position adapter", "" + position);
Product product = (Product) products.get(position);
arguments.putParcelable("singleProduct", product);

// Start a new fragment
fragment = new ProductDetailFragment();
fragment.setArguments(arguments);

FragmentTransaction transaction = activity
.getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.promofragment, fragment,
ProductDetailFragment.ARG_ITEM_ID);
transaction.addToBackStack(ProductDetailFragment.ARG_ITEM_ID);
transaction.commit();
}
});
imageLoader.displayImage(
((Product) products.get(position)).getImageURL(), mImageView,
options, imageListener);
container.addView(view);
return view;
}

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

@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}

private static class ImageDisplayListener extends SimpleImageLoadingListener {

static final List<String> displayedImages = Collections
.synchronizedList(new LinkedList<String>());

@Override
public void onLoadingComplete(String imageUri, View view,
Bitmap loadedImage) {
if (loadedImage != null) {
ImageView imageView = (ImageView) view;
boolean firstDisplay = !displayedImages.contains(imageUri);
if (firstDisplay) {
FadeInBitmapDisplayer.animate(imageView, 500);
displayedImages.add(imageUri);
}
}
}
}
}

My Apps Screenshoot

最佳答案

    Use FrameLayout instead of RelativeLayout

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

<ImageView
android:id="@+id/image_display"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:contentDescription="@string/txt_image_slider" />

</FrameLayout>

关于java - ImageView 填充空白 ViewPager Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32826310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com