2016-07-16 16 views
0

PageViewerのImageViewに動物の画像を表示するAndroid用アプリケーションを開発しています。ほとんどの携帯電話で、すべてがうまく見えます。しかし、私のS7(画像の解像度よりも高い解像度)では、画像を伸ばしてデバイスの幅を広げることができません。ViewPagerのimageViewに画像を伸ばしてください

また、imageViewにはXamarin PhotoView Attacherが付属していますが、私はそれが何の効果もないと思います。私はそれを削除しようとしたが、それはまだ同じです。

私は既にandroid:adjustViewBoundsとすべてのandroid:scaleTypeを試しましたが、残念ながらそれは役に立たなかったです。ここで

私のXMLコードです:活動XMLの パート:

<fieldguideapp.droid.MyViewPager 
    android:id="@+id/pagerAnimalProfile" 
    android:layout_width="match_parent" 
    android:background="#000000" 
    android:layout_height="wrap_content" /> 

PagerLayout:ポケットベルの高さを変更するコードの

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:adjustViewBounds="true" 
     android:id="@+id/imgPagerLayoutImageView" /> 
    <RelativeLayout 
     android:id="@+id/relLayoutImgPagerImageDesc" 
     android:orientation="horizontal" 
     android:layout_width="match_parent" 
     android:gravity="center" 
     android:layout_height="wrap_content" 
     android:background="#FFFFFFFF" 
     android:layout_gravity="bottom"> 
     <TextView 
      android:text="Image desc" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="#FFFFFFFF" 
      android:textColor="#FF000000" 
      android:id="@+id/txtImgPagerImageDescription" 
      android:layout_alignParentLeft="true" /> 
     <LinearLayout 
      android:id="@+id/linLayoutImgPagerIndicator" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:layout_centerHorizontal="true" 
      android:layout_alignBottom="@id/txtImgPagerImageDescription" /> 
     <TextView 
      android:text="Image credit" 
      android:textAppearance="?android:attr/textAppearanceSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="#FFFFFFFF" 
      android:textColor="#FF000000" 
      android:id="@+id/txtImgPagerImageCredit" 
      android:layout_alignParentRight="true" 
      android:layout_alignBottom="@id/linLayoutImgPagerIndicator" /> 
    </RelativeLayout> 
</LinearLayout> 

パート:

// To specify the height of the pager, select the highest child 
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) 
{ 
    int height = 0; 
    for (int i = 0; i < ChildCount; i++) 
    { 
     View child = GetChildAt(i); 
     child.Measure(widthMeasureSpec, MeasureSpec.MakeMeasureSpec(0, MeasureSpecMode.Unspecified)); 
     int h = child.MeasuredHeight; 
     if (h > height) height = h; 
    } 
    if (Resources.Configuration.Orientation == Android.Content.Res.Orientation.Portrait) 
    { 
     heightMeasureSpec = MeasureSpec.MakeMeasureSpec(height, MeasureSpecMode.Exactly); 
    } 
    base.OnMeasure(widthMeasureSpec, heightMeasureSpec); 
} 

編集:ここに私が得るもの: Portrait Landscape

私は何か助けやアドバイスをいただきありがとうございます。ありがとう

+0

問題があるスクリーンショットを投稿できますか?また、fitXYとcenterCropをscaleTypeで試してみましたか? – jonathanrz

+0

@jonathanrzはい、私はfitXYとcenterCropを試しました。残念ながら、私を助けなかった! –

+0

scaleType = fitXY必要な処理を行う必要があります。私はあなたがfitXYを配置し、adjustViewBoundsをテストのために削除することはできますか? – jonathanrz

答えて

0

私は結局Bitmap.CreateScaledBitmap()メソッドを使用して画面の寸法に合わせて手動で画像のサイズを変更し、ImageView.SetImageDrawable()を使用してそれを設定し、完全に動作します。 OutOfMemoryExceptionを避けるために、前後にGC.Collect()に電話する必要があります。

これは理想的ではありませんが、動作します。

関連する問題