2017-01-24 13 views
1

Android TV用のアプリを開発中で、leanbackライブラリを使用しています。Android TV ImageCardViewのタイトルラッピング

Googleからexampleには、public class CardPresenter extends Presenterを使用してコンテンツを表示しています。問題は、すべてのテキストをタイトルに表示する、つまりそれをカットしないことです。

enter image description here

私はすでに試した:

1)プログラムでLayoutParamsを設定することで、この問題を解決するには:cardView.findViewById(R.id.title_text).setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT));

2)私はImageCardためlb_image_card_view.xmlファイル内に見えました。面白い瞬間、idが "title_text"のTextViewは既にandroid:layout_height="wrap_content"のパラメータを持っていますが、うまくいかないようですね??バグですか?

3)バックアップ計画では、ImageCardView用に独自のクラスを作成できますが、この解決策は2つ難しいようです。

Thx。

は、私は以下の回答を使用しますが、私は、パフォーマンスを向上させるためのコードをmodificativeする必要があります。

cardView.setOnFocusChangeListener((view, isFocused) -> { 
     if (isFocused) { 
      ((TextView) cardView.findViewById(R.id.title_text)).setMaxLines(5); 
     } 
     else { 
      ((TextView) cardView.findViewById(R.id.title_text)).setMaxLines(1); 
     } 
    }); 

答えて

2

それはあなたを助けることができる場合は、このtutorialをチェックしてみてください。タイトルのすべてのテキストを表示または表示するのに役立ちます。ここで

は、このチュートリアル

@Override 
public ViewHolder onCreateViewHolder(ViewGroup parent) { 
    final ImageCardView cardView = new ImageCardView(mContext);  

    cardView.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
     @Override 
     public void onFocusChange(View view, final boolean isFocused) { 
      final View infoField = view.findViewById(R.id.info_field); 
      final TextView contentField = (TextView)view.findViewById(R.id.content_text); 
      final TextView titleField = (TextView)view.findViewById(R.id.title_text); 
      final Drawable mainImage = ((ImageView)view.findViewById(R.id.main_image)).getDrawable(); 

      if (isFocused) { 
       ((TextView)cardView.findViewById(R.id.title_text)).setMaxLines(3); 
       FrameLayout.LayoutParams infoLayout = new FrameLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
       infoField.setLayoutParams(infoLayout); 
       RelativeLayout.LayoutParams contentLayout = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); 
       contentLayout.addRule(RelativeLayout.BELOW, R.id.title_text); 
       contentField.setLayoutParams(contentLayout); 
      } 
      else { 
       ((TextView)cardView.findViewById(R.id.title_text)).setMaxLines(1); 
      } 
     } 
    }); 

    cardView.setFocusable(true); 
    cardView.setFocusableInTouchMode(true); 
    cardView.setBackgroundColor(mContext.getResources().getColor(R.color.fastlane_background)); 
    return new ViewHolder(cardView); 
} 

そして、ここでのコードの使用は、このコードの出力です。

enter image description here

詳細については、このthreadを確認してください。

関連する問題