我是为 Android TV 开发应用程序并使用 Leanback 库。在谷歌的示例中,他们使用
public class CardPresenter extends Presenter
来显示内容。问题是,我希望在标题中显示所有文本,即不剪切它。
我已经尝试过:
1)通过编程方式设置LayoutParams来解决这个问题:cardView.findViewById(R.id.title_text).setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
2)我查看了lb_image_card_view.xml文件中的ImageCard。有趣的是,具有id“title_text”的TextView已经具有android:layout_height =“wrap_content”
参数,但看起来它不起作用? 这是一个错误吗?
3)备用计划是为ImageCardView创建自己的类,但这种解决方案似乎太难了。
谢谢。
更新。
我使用了下面的答案,但我必须修改代码以获得更好的性能:
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);
}
});