2017-07-20 8 views
0

私は多くの異なるCardViewを保持するRecyclerViewを作成しました。 RecyclerViewが初めてロードされるとき、リサイクラビューで表示される画面上で開始するカードは正しいサイズですが、スクリーンからスクロールすると、次にスクリーンに戻ったときにサイズが変更され、サイズが間違っています。RecyclerViewのCardViewは、表示するときにサイズを変更します

アクションで、それのビデオ:https://gfycat.com/gifs/detail/SoupyPowerlessFulmar

LocationsListFragment:(偽のgetContext()、LinearLayoutManager.VERTICAL、)

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
    // Inflate the layout for this fragment 
    View v = inflater.inflate(R.layout.fragment_locations_list, container, false); 
    adapter = new LocationsAdapter(mParam1); 

    RecyclerView recyclerView = (RecyclerView)v.findViewById(R.id.recycler_locations); 
    recyclerView.setHasFixedSize(true); 
    recyclerView.setAdapter(adapter); 

    L 

inearLayoutManagerのlayoutManager =新しいLinearLayoutManager。 recyclerView.setLayoutManager(layoutManager);

return v; 
} 

LocationsViewHolder:

public class LocationsViewHolder extends RecyclerView.ViewHolder{ 

private ImageView locationImage; 
private TextView locationName; 
private TextView locationAddress; 

public LocationsViewHolder(View itemView) { 
    super(itemView); 

    locationName = (TextView)itemView.findViewById(R.id.location_name); 
    locationAddress = (TextView)itemView.findViewById(R.id.location_address); 
    locationImage = (ImageView) itemView.findViewById(R.id.location_image); 
} 

public void updateUI(HashMap<String, String > place){ 
    locationName.setText(place.get("name")); 
} 

} 

LocationsAdapter:

public class LocationsViewHolder extends RecyclerView.ViewHolder{ 

private ImageView locationImage; 
private TextView locationName; 
private TextView locationAddress; 

public LocationsViewHolder(View itemView) { 
    super(itemView); 

    locationName = (TextView)itemView.findViewById(R.id.location_name); 
    locationAddress = (TextView)itemView.findViewById(R.id.location_address); 
    locationImage = (ImageView) itemView.findViewById(R.id.location_image); 
} 
public void updateUI(HashMap<String, String > place){ 
    locationName.setText(place.get("name")); 
} 

} 

card_location.xml:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/card"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:gravity="center_vertical"> 
     <LinearLayout 
      android:layout_width="274dp" 
      android:layout_height="match_parent" 
      android:orientation="vertical" 
      android:layout_margin="15dp"> 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Test" 
       android:textColor="#2f2f2f" 
       android:textSize="18dp" 
       android:id="@+id/location_name"/> 

      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="Address Goes Here" 
       android:textSize="16dp" 
       android:paddingTop="5dp" 
       android:id="@+id/location_address"/> 

     </LinearLayout> 

     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="80dp" 
      android:src="@drawable/ic_restaurant_black_24dp" 
      android:adjustViewBounds="true" 
      android:scaleType="centerCrop" 
      android:id="@+id/location_image" 
      android:layout_margin="10dp"/> 

    </LinearLayout> 

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

私はそれが必要な情報のすべてでなければならないと思います。他に何かがあれば私に知らせてください。

ありがとうございました。ラップコンテンツとしてcardviewの

+0

変更高さ:layout_height = "wrap_parent" – dharmx

答えて

0

変更高ラップコンテンツ=>アンドロイドなどcardviewの

android:layout_height="wrap_parent" 
関連する問題