0

私はview pagerを作成しました。それはサーバーから来る画像を持っています。 画像の解像度は980X551です。Androidで画像のアスペクト比を乱すことなく画像を伸ばす方法は?

この画像を画面の半分に表示する必要があります。

ViewPage Layoutでは、画像のwidthXheightmatch_parentに設定しました。

と私のMainActivityでは、私は身長を使用してViewPagerの高さを定義します。私は半分の画面にその高さを設定するとき

問題は私のMain Activityで、私はそのスタートが伸び、 画像の高さを増加させ、そして、私は半分のページでこれを表示するために必要がある場合、ということです。、そしてそれ はかなりのストレッチに見えました。

親切アンドロイド

に画像のアスペクト比を乱すことなく、画像をストレッチする方法を私を導い

ビューポケットベルコード

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    > 


    <ImageView 
     android:id="@+id/image_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:adjustViewBounds="true" 
     android:scaleType="fitCenter" 
     /> 

</RelativeLayout> 

主な活動

<FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
     android:layout_weight="6" 
     android:id="@+id/frameLayout2" 

     > 

     <android.support.v4.view.ViewPager 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:id="@+id/viewPager" 
      android:adjustViewBounds="true" 
      android:scaleType="fitCenter" 
      /> 
+0

あなたは完全なレイアウトファイルを提供することはできますか?画像が伸びていて、切り取られていないことを確かめていますか? – skywall

+0

はい、伸ばして、レイアウトコードを追加しています – Kirmani88

答えて

1

使用Pisasso library Android用

他の多くのオプションの中で、イメージを読み込んでサイズを変更することができます。

例のコードは次のようになります。

Picasso.with(context) 
    .load(url) 
    .resize(screeWidth/2, screen height/2) 
    .centerCrop() 
    .into(imageView); 
1

centerCropオプションは、あなたの状況に合うかもしれません。 adjustViewBoundsは不要です。このような

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:orientation="vertical" android:layout_width="match_parent" 
       android:layout_height="match_parent"> 


    <ImageView 
      android:id="@+id/image_view" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:scaleType="centerCrop"/> 

</RelativeLayout> 
関連する問題