2017-06-20 8 views
-2

各アイテムはその下にTextViewがあり、アイテムの下にシェイプを付けたImageViewであるRecyclerViewでレイアウトを作成しました。スケーリングに関する問題RecyclerViewアイテム

縦向きでは、画像が横長のときに画像全体が表示されないという問題があります。

肖像例:

風景例:

activity.xml:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/coordlayout" > 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/appbarlayout"> 

     <android.support.design.widget.CollapsingToolbarLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:id="@+id/collapsingtoolbar" 
      app:layout_scrollFlags="scroll|enterAlways"> 

      <include 
      layout="@layout/toolbar" 
      android:id="@+id/toolbar" 
      app:layout_scrollFlags="scroll|enterAlways" /> 

     </android.support.design.widget.CollapsingToolbarLayout> 
    </android.support.design.widget.AppBarLayout> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/recyclerview" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/appbarlayout" 
     app:layout_behavior="@string/appbar_scrolling_view_behavior"> 

    </android.support.v7.widget.RecyclerView> 

</android.support.design.widget.CoordinatorLayout> 

recyclerview_item.xml:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginBottom="5dp" > 

    <ImageView 
     android:id="@+id/flIcon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="@string/freelancer_s_portrait" 
     android:background="@drawable/menu_square" 
     app:srcCompat="@drawable/rampart_pt" 
     android:padding="3dp" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintTop_toTopOf="parent" /> 

    <TextView 
     android:id="@+id/flName" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="@drawable/menu_square" 
     android:gravity="center" 
     android:text="Asana" 
     android:textAppearance="@android:style/TextAppearance.DeviceDefault.Medium.Inverse" 
     app:layout_constraintLeft_toLeftOf="parent" 
     app:layout_constraintRight_toRightOf="parent" 
     app:layout_constraintTop_toBottomOf="@+id/flIcon" /> 

</android.support.constraint.ConstraintLayout> 

どうすれば修正できますか?

答えて

0

imageviewのscaleTypeプロパティを設定できますが、画像が歪んでいる可能性があります。あなたの代わりにあなたの所望の高さの実際の画像をJPGの高さを持つことになりますImageViewwrap_contentを使用する場合は

android:scaleType="fitXY" 
+0

ビューが画像の高さを小さくするだけでなく、画像を伸ばす必要がない理由が分かりますか? –

0

あなたは

android:scaleType="centerCrop"

を使用することができます。

ただし、独自の高さdpsを使用することができます。

関連する問題