2016-06-15 4 views
0

Это код cardpresenter.java здесь card_width и высота определена, но это не следует в андроида KitKatCard Presenter расширяется в Android 4.4 при выборе

`

package com.example.sahilbhatoa.iitv; 

import android.graphics.drawable.Drawable; 
import android.support.v17.leanback.widget.ImageCardView; 
import android.support.v17.leanback.widget.Presenter; 
import android.util.Log; 
import android.view.ViewGroup; 

import com.bumptech.glide.Glide; 

/* 
* A CardPresenter is used to generate Views and bind Objects to them on demand. 
* It contains an Image CardView 
*/ 
public class CardPresenter extends Presenter { 
    private static final String TAG = "CardPresenter"; 

    private static final int CARD_WIDTH = 313; 
    private static final int CARD_HEIGHT = 176; 
    private static int sSelectedBackgroundColor; 
    private static int sDefaultBackgroundColor; 
    private Drawable mDefaultCardImage; 

    private static void updateCardBackgroundColor(ImageCardView view, boolean selected) { 
     int color = selected ? sSelectedBackgroundColor : sDefaultBackgroundColor; 
     // Both background colors should be set because the view's background is temporarily visible 
     // during animations. 

     view.setBackgroundColor(color); 
     view.findViewById(R.id.info_field).setBackgroundColor(color); 
    } 

    @Override 
    public ViewHolder onCreateViewHolder(ViewGroup parent) { 
     Log.d(TAG, "onCreateViewHolder"); 

     sDefaultBackgroundColor = parent.getResources().getColor(R.color.default_background); 
     sSelectedBackgroundColor = parent.getResources().getColor(R.color.selected_background); 
     mDefaultCardImage = parent.getResources().getDrawable(R.drawable.movie); 

     ImageCardView cardView = new ImageCardView(parent.getContext()) 

     { 
      @Override 
      public void setSelected(boolean selected) { 
       updateCardBackgroundColor(this, selected); 
       super.setSelected(selected); 
      } 
     }; 

     cardView.setFocusable(true); 
     cardView.setFocusableInTouchMode(true); 
     updateCardBackgroundColor(cardView, false); 
     return new ViewHolder(cardView); 
    } 

    @Override 
    public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) { 

     ImageCardView cardView = (ImageCardView) viewHolder.view; 
     cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT); 
     if (item instanceof Movie) 
     { 
      Movie movie = (Movie) item; 
      Log.d(TAG, "onBindViewHolder"); 
      if (movie.getCardImageUrl() != null) { 
       cardView.setTitleText(movie.getTitle()); 
       cardView.setContentText(movie.getCategory()); 
       cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT); 
       Glide.with(viewHolder.view.getContext()) 
         .load(movie.getCardImageUrl()) 
         .centerCrop() 
         .error(mDefaultCardImage) 
         .into(cardView.getMainImageView()); 
      } 
     } 
     else 
     { 
      cardView.setTitleText(item.toString()); 
      cardView.setMainImageDimensions(CARD_WIDTH, CARD_HEIGHT); 

      if (item.toString().equalsIgnoreCase("categories")) 
       Glide.with(viewHolder.view.getContext()) 
        .load(R.drawable.categories) 
        .centerCrop() 
        .error(mDefaultCardImage) 
        .into(cardView.getMainImageView()); 
      else if (item.toString().equalsIgnoreCase("Account Summary")) 
       Glide.with(viewHolder.view.getContext()) 
         .load(R.drawable.account_summary) 
         .centerCrop() 
         .error(mDefaultCardImage) 
         .into(cardView.getMainImageView()); 
      else if (item.toString().equalsIgnoreCase("Video On Demand")) 
       Glide.with(viewHolder.view.getContext()) 
         .load(R.drawable.videoondemand) 
         .centerCrop() 
         .error(mDefaultCardImage) 
         .into(cardView.getMainImageView()); 
      else if (item.toString().equalsIgnoreCase("Customer Support")) 
       Glide.with(viewHolder.view.getContext()) 
         .load(R.drawable.customer_support) 
         .centerCrop() 
         .error(mDefaultCardImage) 
         .into(cardView.getMainImageView()); 
      else if (item.toString().equalsIgnoreCase("Favorites")) 
       Glide.with(viewHolder.view.getContext()) 
         .load(R.drawable.favourites) 
         .centerCrop() 
         .error(mDefaultCardImage) 
         .into(cardView.getMainImageView()); 

     } 


    } 

    @Override 
    public void onUnbindViewHolder(Presenter.ViewHolder viewHolder) { 
     Log.d(TAG, "onUnbindViewHolder"); 
     ImageCardView cardView = (ImageCardView) viewHolder.view; 
     // Remove references to images so that the garbage collector can free up memory 
     cardView.setBadgeImage(null); 
     cardView.setMainImage(null); 
    } 
} 

`

In this the Card view works perfectly with same code just OS is android 5.0.1

Card View expands to full screen .Here the OS is Android 4.4.3

ответ

0

Я думаю, что для этого есть bug report. Возможно, что все API до API 21 может иметь эту проблему. Вы можете захотеть следовать этому, чтобы обновить эту проблему. Тем временем попробуйте использовать версию API версии 21 и выше. Надеюсь, это поможет

Смежные вопросы