2013-10-27 107 views
2

我的圖像沒有完全適應屏幕。在頂部和底部獲得白色邊框 我的圖像有700x1002。PageViewer頂部和底部的白色邊框

請有人可以幫助我得到這些邊緣,使圖像/容器完全適合屏幕?

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:

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; 
    } 
} 

回答

3

試圖改變自己的view.setScaleType(ScaleType.FIT_CENTER);view.setScaleType(ScaleType.CENTER_CROP);

0

它來得有點遲,但沒有解決的上述沒有爲工作我。所以想到分享我的解決方案,完美的作品。 如果我們在視圖中設置ScaleType和Params(ImageView),那麼我們可能會面對LinerLayout/RelativeLayout的問題。 所以,只需在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" 
    /> 

相關問題