简体   繁体   English

PageViewer白色边框在顶部和底部

[英]PageViewer white borders on top and bottom

My image is not adapting the screen completely. 我的图像无法完全适应屏幕。 Is getting with white borders at the top and bottom My images have 700x1002. 顶部和底部出现白色边框我的图像尺寸为700x1002。

Please can someone help me get these edges and make the image/container fully fit the screen? 请有人能帮助我获得这些边缘并使图像/容器完全适合屏幕吗?

layout.xml: layout.xml:

<?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" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linearActions" >

        <android.support.v4.view.ViewPager
            android:id="@+id/tourImageViewPager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </android.support.v4.view.ViewPager>
    </FrameLayout>

    <LinearLayout
        android:id="@+id/linearActions"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="@color/tour_bg"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btnIdentify"
            android:layout_width="wrap_content"
            android:layout_height="45dp"
            android:layout_marginBottom="24dp"
            android:layout_marginLeft="30dp"
            android:background="@color/buttonColorWhite"
            android:layout_marginTop="27dp"
            android:textSize="16sp"/>

        <Button
            android:id="@+id/btnGoHome"
            android:layout_width="wrap_content"
            android:layout_height="45dp"
            android:layout_marginBottom="24dp"
            android:layout_marginLeft="60dp"
            android:layout_marginRight="30dp"
            android:layout_marginTop="27dp"
            android:background="@color/buttonColorBlue"
            android:textSize="16sp"/>
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/relativeCircle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/linearActions"
        android:layout_marginBottom="24dp"
        android:background="@null" >

        <com.viewpagerindicator.CirclePageIndicator
            android:id="@+id/tourImageIndicator"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            app:fillColor="#027CC3"
            app:pageColor="#CCCCCC" />
    </RelativeLayout>

</RelativeLayout>

MyAdapter: MyAdapter:

public class MyAdapter extends PagerAdapter {

    Activity activity;
    int imageArray[];

    public MyAdapter(Activity act, int[] imgArray) {
        imageArray = imgArray;
        activity = act;
    }

    public Object instantiateItem(View collection, int position) {
        ImageView view = new ImageView(activity);
        view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT));
        view.setScaleType(ScaleType.FIT_CENTER);
        view.setImageResource(imageArray[position]);
        ((ViewPager) collection).addView(view, 0);
        return view;
    }

     @Override
     public void destroyItem(View arg0, int arg1, Object arg2) {
      ((ViewPager) arg0).removeView((View) arg2);
     }

     @Override
     public boolean isViewFromObject(View arg0, Object arg1) {
      return arg0 == ((View) arg1);
     }

    @Override
    public int getCount() {
        return imageArray.length;
    }

    @Override
    public Parcelable saveState() {
        return null;
    }
}

try to change your view.setScaleType(ScaleType.FIT_CENTER); 尝试更改您的view.setScaleType(ScaleType.FIT_CENTER); to view.setScaleType(ScaleType.CENTER_CROP); 查看view.setScaleType(ScaleType.CENTER_CROP);

Its little bit late but none of the solution stated above did not work for me. 它有点晚了,但是上述解决方案对我都不起作用。 So thought of sharing my solution which perfectly works. 因此,想到了共享我的解决方案的完美方法。 If we set the ScaleType and Params in view(ImageView) then we might face problems either with LinerLayout/RelativeLayout. 如果在view(ImageView)中设置ScaleType和Params,则LinerLayout / RelativeLayout可能会遇到问题。 So just set the ScaleType of ImageView something like below in viewpagerAdapter layout. 因此,只需在viewpagerAdapter布局中像下面一样设置ImageView的ScaleType即可。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:src="@drawable/sampleImage"
    android:id="@+id/img_pager_item"
    android:scaleType="center"
    android:clickable="false"
    />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM