【发布时间】:2016-08-14 15:27:09
【问题描述】:
我正在尝试使用 Leanback 创建一排操作项,这些操作项位于视频播放器中播放器控制栏上方的中心位置。
操作项是可操作的图像视图的 ListRow(表示表情符号反应)。
我的问题:我无法让它们位于中心位置,就像主要和次要控制栏位于播放器的中心一样。当前列表行显示如下:
这是定义单个操作的 XML 布局:
<?xml version="1.0" encoding="utf-8"?>
<com.makeramen.roundedimageview.RoundedImageView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/rounded_image_view"
android:src="@drawable/ic_action_insert_emoticon"
android:scaleType="fitStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:riv_corner_radius="30dip"
app:riv_border_width="2dip"
app:riv_border_color="#333333"
app:riv_tile_mode="repeat"
app:riv_oval="true">
</com.makeramen.roundedimageview.RoundedImageView>
以及实例化每个行项目的演示者:
public class RoundedViewPresenter extends Presenter {
private static final String TAG = RoundedViewPresenter.class.getSimpleName();
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View rootView = inflater.inflate(R.layout.rounded_image_view, parent, false);
RoundedImageView roundedImageView = (RoundedImageView) rootView.findViewById(R.id.rounded_image_view);
//roundedImageView.mutateBackground(true);
//roundedImageView.setBackground(backgroundDrawable);
roundedImageView.setFocusable(true);
roundedImageView.setFocusableInTouchMode(true);
((HorizontalGridView)parent).setGravity(Gravity.CENTER);
return new ViewHolder(roundedImageView);
} ...
然后像这样在播放器的片段中添加行:
// add emoji rows
...
ArrayObjectAdapter emojiRowAdapter = new ArrayObjectAdapter(new RoundedViewPresenter());
emojiRowAdapter.add(mObjectModel0);
emojiRowAdapter.add(mObjectModel1);
emojiRowAdapter.add(mObjectModel2);
emojiRowAdapter.add(mObjectModel3);
ListRow emojiRow = new ListRow(emojiRowAdapter);
mRowsAdapter.add(emojiRow);
...
我已经尝试了 android:layout_gravity="center" 和程序化 HorizontalGridView.setGravity() 方法,但均未成功。
知道为什么,和/或使行居中的替代方法吗?
【问题讨论】:
-
直接在
Play Back Overlay Activity Layout中进行,而不是膨胀另一个圆形图像视图布局,这只会满足您的要求。据我所知,它们不是您可以以编程方式执行的任何其他方法。 -
@jaydroider,我不能在 Activity 中充气,因为我们需要这个自定义行来覆盖视频播放,就像播放器控件行被覆盖一样。这将确保自定义行在播放过程中与其他辅助视图一起消失,并在 dpad 操作时重新出现
标签: android android-layout android-recyclerview android-tv leanback