У меня есть постоянный нижний лист с рамкой. Я хочу сделать полноэкранный нижний лист, но не могу.
activity_main.xml
<android.support.design.widget.CoordinatorLayout 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="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:layout_gravity="center"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<Button
android:id="@+id/open_fragment1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="open F1" />
<Button
android:id="@+id/open_fragment2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="open F2" />
<Button
android:id="@+id/modal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="modal" />
</LinearLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/nested"
app:layout_anchorGravity="bottom"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="true"
app:behavior_hideable="true"
app:behavior_peekHeight="0dp"
app:layout_behavior="@string/bottom_sheet_behavior">
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.NestedScrollView>
ActivityMain.java
public class ActivityMain extends AppCompatActivity {
BottomSheetBehavior bottomSheetBehavior;
Button openF1, openF2, modal;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
openF1 = (Button) findViewById(R.id.open_fragment1);
openF2 = (Button) findViewById(R.id.open_fragment2);
modal = (Button) findViewById(R.id.modal);
View nested = findViewById(R.id.nested);
bottomSheetBehavior = BottomSheetBehavior.from(nested);
openF1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
setFragment(0);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
});
openF2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
setFragment(1);
bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
});
modal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
BottomSheet bottomSheet = new BottomSheet();
bottomSheet.show(getSupportFragmentManager(), "tag");
}
});
bottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
String state = "N/A";
switch (newState) {
case BottomSheetBehavior.STATE_COLLAPSED:
state = "collapsing";
break;
case BottomSheetBehavior.STATE_DRAGGING:
state = "draging";
break;
case BottomSheetBehavior.STATE_SETTLING:
state = "setting";
break;
case BottomSheetBehavior.STATE_EXPANDED:
state = "expanding";
break;
case BottomSheetBehavior.STATE_HIDDEN:
state = "hidden";
break;
}
Toast.makeText(ActivityMain.this, state, Toast.LENGTH_SHORT).show();
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
}
public void setFragment(int state) {
if (state == 0) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment1 fragment1 = new Fragment1();
ft.replace(R.id.frame, fragment1);
ft.commit();
}else if (state==1){
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment2 fragment2 = new Fragment2();
ft.replace(R.id.frame, fragment2);
ft.commit();
}
}
}
fragment1.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#1e1e1e">
<TextView
android:layout_gravity="center"
android:textColor="#fff"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="frahment1" />
fragment2.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#9d4000ff"
tools:context="sarekouche.ir.map2.Fragment2">
<TextView
android:layout_gravity="center"
android:textColor="#fff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fragment 2" />
Когда я щелкаю, чтобы открыть нижний лист, нижний лист раскрывается, но фрагмент не является полноэкранным, это всего лишь textView
, что есть во фрагменте.