我需要一个底部弹出框在平板上不占据全部宽度。但是它无视xml中的layout_width
属性。我该如何做呢?
我的底部弹出框类:
public class DetailsFragment extends BottomSheetDialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//Create fragment root view
View view = inflater.inflate(R.layout.fragment_details, container, false);
//Set toolbar
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
Drawable icClose = VectorDrawable.getDrawable(getContext(), R.drawable.ic_close_white_24dp);
toolbar.setNavigationIcon(icClose);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
toolbar.inflateMenu(R.menu.details);
RecyclerView rvContent = (RecyclerView) view.findViewById(R.id.rvContent);
FullExpandedListManager lm = new FullExpandedListManager(getContext());
rvContent.setLayoutManager(lm);
rvContent.setHasFixedSize(true);
rvContent.setAdapter(mAdapter);
return view;
}
}
onCreate
中添加以下行:getWindow().setLayout(300 /*我们的宽度*/, ViewGroup.LayoutParams.MATCH_PARENT);
,似乎可以为BottomSheetDialog
解决问题。 - JohnListView
中,则某些按钮触摸事件将无法注册。撤销此更改后,所有问题都消失了。因此,请自行决定是否使用。 - Adam Burley