I'm trying to create a row of action items that sits centered just above the player controls bar in a video player using Leanback.
The action items are a ListRow of image views that are actionable (to represent emoticon reactions).
My problem: I can't get them to position in the center, just like the primary and secondary controls bar are centered on the player. The current list row appears like this:
Here's the XML layout that defines an individual action:
<?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>
And the presenter that instantiates each row item:
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);
} ...
And then add the rows in the player's fragment like this:
// 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);
...
I have tried both the android:layout_gravity="center" and programmatic HorizontalGridView.setGravity() approaches without success.
Any idea why, and/or alternative methods to center the row?