所以这个问题出于某种原因在BrowseFrameLayout中,并且为了解决这个问题,我必须重写onFocusSearchListener并自己管理焦点。
在BrowseFragment我伸出我有这样的方法:
public void workaroundFocus(){
if(getView() != null) {
View viewToFocus = getActivity().findViewById(R.id.view_to_focus);
BrowseFrameLayout browseFrameLayout = getView().findViewById(android.support.v17.leanback.R.id.browse_frame);
browseFrameLayout.setOnFocusSearchListener((focused, direction) -> {
if (direction == View.FOCUS_UP) {
return viewToFocus;
}
else {
return null;
}
});
}
}
然后:
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
workaroundFocus();
/*
Rest of the code
*/
}
瞧它的工作原理。
由于您使用了'RelativeLayout',因此您应该提供布局xml文件的内容。这将给我们提供组件顺序的线索。 – dan
@dan我更新的结构我不使用除浏览片段内的行之外的任何东西 – user3820641
'RelativeLayout'提供的属性如:'android:layout_alignParentTop'或'android:layout_toRightOf'等等。请参阅[这里](https://developer.android .com/guide/topics/ui/layout/relative.html)获取完整列表。这就是为什么重要的是要看到什么是使用的配合。 – dan