У меня есть собственный класс, расширяющий BottomSheetDialogFragment, который будет отображаться при нажатии кнопки. Мой пользовательский макет BottomSheetDialogFragment состоит из 3 частей.
aA Текст заголовка,
bA радиогруппа (к которой я динамически добавляю n элементов)
c. Кнопка OK внизу(который я хотел отобразить всегда внизу)
Вот так это выглядит при нажатии моей кнопки. ![enter image description here](https://i.stack.imgur.com/XVoZv.jpg)
На самом деле, когда мой фрагмент диалога запускается впервые, моя кнопка ОК не отображается. Однако когда я раскрываю BottomSheet, она выглядит так, как показано ниже имоя кнопка ОК видна ![enter image description here](https://i.stack.imgur.com/DKjAb.jpg)
Но мне нужно всегда показывать нижнюю кнопку ОК, т. е. при запуске фрагмента диалога моя кнопка ОКдолжен присутствовать внизу, независимо от количества переключателей, которые он имеет, и когда он развернут, тогда кнопка «ОК» должна быть внизу, и мои переключатели должны быть прокручиваемыми .
Ниже моемакет фрагмента диалога:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nested_scroll_view"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="25dp"
android:layout_marginRight="20dp"
android:layout_alignParentTop="true"
android:text=""
/>
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:layout_marginLeft="15dp"
android:layout_below="@id/title"
android:layout_marginBottom="10dp"
>
</RadioGroup>
<android.widget.Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ok"
android:layout_below="@id/radiogroup"
android:text="OK"
android:layout_marginTop="10dp"
android:layout_alignParentBottom="true"
></android.widget.Button>
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
Это мой пользовательский BottomSheetDialogFragment
public class BottomSheetExample extends BottomSheetDialogFragment {
@BindView(R.id.title)
TextView title;
@BindView(R.id.ok)
Button ok;
@BindView(R.id.nested_scroll_view)
NestedScrollView nestedScrollView;
@BindView(R.id.radiogroup)
RadioGroup radioGroup;
// TODO: Rename and change types of parameters
public BottomSheetExample() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.bottom_sheet, container, false);
ButterKnife.bind(this, view);
ArrayList<String> list = new ArrayList<>();
for(int i=0;i<15;i++){
list.add(""+i);
}
title.setText("Numbers");
RadioGroup rg = radioGroup;
for (int i = 0; i < list.size(); i++) {
RadioButton rbn = new RadioButton(getContext());
rbn.setId(View.generateViewId());
String radioButtonText = list.get(i);
rbn.setText(radioButtonText);
rg.addView(rbn);
}
return view;
}
}
Вот как я называю свой нижний лист:
BottomSheetExample bottomSheet = new BottomSheetExample();
bottomSheet.showNow(this.getSupportFragmentManager(), "tag");
Любые входные данные будут очень полезны. Заранее спасибо!