答案 0 :(得分:0)
您应该能够使用像这样的布局来实现这一目标,这种布局在我的情况下适用:
<androidx.coordinatorlayout.widget.CoordinatorLayout>
<View
android:id="@+id/bottomSheet"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"/>
<View android:id="@+id/viewYouWantAbove>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
因此,您希望位于底部表格上方的视图仅需位于xml中底部表格之后。
注意:如果您的底部工作表具有高程,则另一个视图必须具有较高或相等的高程。
答案 1 :(得分:-1)
是的,您可以在底部表格后面显示任何控件我提供我的代码..
在这段代码中,我在地图布局中使用了底页显示,你可以根据需要进行管理..
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include layout="@layout/bottom_sheet" />
</android.support.design.widget.CoordinatorLayout>
然后制作bottom_sheet xml
<?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:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:orientation="vertical"
android:padding="20dp"
app:behavior_hideable="true"
app:behavior_peekHeight="100dp"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:weightSum="3">
<TextView
android:id="@+id/flTvData"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="Order Details"
android:textColor="#444"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="@+id/flTvKm"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:textSize="15dp"
android:textStyle="bold"></TextView>
</LinearLayout>
<TextView
android:id="@+id/flTvDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
然后在main_activity中使用..
private BottomSheetBehavior behavior;
private LinearLayout layoutBottomSheet;
layoutBottomSheet=findViewById(R.id.bottom_sheet);
mTvData = findViewById(R.id.flTvData);
mTvKm = findViewById(R.id.flTvKm);
mTvDuration = findViewById(R.id.flTvDuration);
BottomSheetBehavior.from(layoutBottomSheet).setState(BottomSheetBehavior.STATE_EXPANDED);
behavior=BottomSheetBehavior.from(layoutBottomSheet);
你可以处理点击事件或管理扩展等事情。
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() {
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
switch (newState) {
case BottomSheetBehavior.STATE_HIDDEN:
break;
case BottomSheetBehavior.STATE_EXPANDED: {
mTvData.setText(endTitle);
mTvKm.setText(km);
mTvDuration.setText(duration);
}
break;
case BottomSheetBehavior.STATE_COLLAPSED: {
}
break;
case BottomSheetBehavior.STATE_DRAGGING:
break;
case BottomSheetBehavior.STATE_SETTLING:
break;
}
}
@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}
});
behavior.setPeekHeight(100);
layoutBottomSheet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (activityCallName.equals("UserPlaceInput")){
Intent intent = new Intent(MapsActivity.this, PlaceDetails.class);
intent.putExtra("placeId", placeId);
startActivity(intent);
}
else {
Intent intent = new Intent(MapsActivity.this, ShowAllSteps.class);
intent.putExtra("Response", response);
startActivity(intent);
}
}
});
}