Android leanback库ListRowPresenter整行扩展

时间:2015-03-17 14:53:35

标签: android android-tv leanback

我试图在leanback图书馆轮播中选择整行展开。

我想要的效果:Effect that I want

我正在使用android TV示例代码。 我尝试过setExpandedRowHeight(..);setRowHeight(..);

/**
 * Created by sylversphere on 15-03-16.
 */
public class ExperimentalFragment extends BrowseFragment{

    private ArrayObjectAdapter mRowsAdapter;
    private ExperimentalCardPresenter mCardPresenter;
    private int NUM_ROWS = 20;
    private int NUM_COLS = 40;
    private Context context;

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        context = getActivity();
        setTitle("Hello there you kid"); // Badge, when set, takes precedent
        setHeadersState(HEADERS_DISABLED);
        loadRows();
    }

    private void loadRows() {
        List<Movie> list = MovieList.setupMovies();

        final ListRowPresenter lrp = new ListRowPresenter(FocusHighlight.ZOOM_FACTOR_LARGE);
        lrp.setRowHeight(100);
        lrp.setExpandedRowHeight(200);

        mRowsAdapter = new ArrayObjectAdapter(lrp);

        mCardPresenter = new ExperimentalCardPresenter();

        int i;
        for (i = 0; i < NUM_ROWS; i++) {
            ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(mCardPresenter);
            for (int j = 0; j < NUM_COLS; j++) {
                listRowAdapter.add(list.get(j % 5));
            }
            mRowsAdapter.add(new ListRow(listRowAdapter));
        }

        setAdapter(mRowsAdapter);
    }

    private void say(String s) {
        Toast.makeText(context, "Say : "+s, Toast.LENGTH_SHORT).show();
    }
}

但行保持不变。我尝试手动动画行,但现在行之间没有适当的填充。 如何使行扩展并保持填充?

1 个答案:

答案 0 :(得分:1)

通过使用setExpandedRowHeight,您只需设置高度,但不会真正扩展行。您需要通过调用setRowViewExpanded方法

显式设置展开的行视图
public final void setRowViewExpanded (Presenter.ViewHolder holder, boolean expanded)