Android 将底杆固定在坐标布局中
我有一个Android 将底杆固定在坐标布局中,android,android-layout,android-toolbar,android-coordinatorlayout,Android,Android Layout,Android Toolbar,Android Coordinatorlayout,我有一个CoordinatorLayout,其中包含AppBarLayout,还有一个FrameLayout,其中包含片段 其中一个片段在顶部包含一个TabLayout,在底部包含一个“自制”工具栏 AppBarLayout配置了app:layout\u scrollFlags=“scroll | enterally” 我的问题是滚动时两个“工具栏”都隐藏了,AppBarLayout和我的“自制”工具栏都在底部。这是目前的行为 我想修复底部的“自制”工具栏以保持可见,但我无法实现 这是片段布局
CoordinatorLayout
,其中包含AppBarLayout
,还有一个FrameLayout
,其中包含片段
其中一个片段在顶部包含一个TabLayout
,在底部包含一个“自制”工具栏
AppBarLayout
配置了app:layout\u scrollFlags=“scroll | enterally”
我的问题是滚动时两个“工具栏”都隐藏了,AppBarLayout和我的“自制”工具栏都在底部。这是目前的行为
我想修复底部的“自制”工具栏以保持可见,但我无法实现
这是片段布局的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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<android.support.design.widget.TabLayout
android:id="@+id/toolbarfilter"
android:layout_width="match_parent"
android:background="@color/azul_asde"
app:tabMode="fixed"
app:tabMaxWidth="0dp"
android:elevation="4dp"
app:tabIndicatorColor="@color/verde_pastel"
android:layout_height="wrap_content"
/>
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/swipeContainer"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<android.support.v7.widget.RecyclerView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/toolbarselection"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:background="@color/azul_asde"
android:elevation="4dp"
android:visibility="visible"
>
<ImageView
android:id="@+id/delete"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_delete_white_24dp"
android:tint="@color/gris_desactivado" />
<ImageView
android:id="@+id/select"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_bookmark_border_white_24dp"/>
<ImageView
android:id="@+id/send"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="@drawable/ic_send_white_24dp"
android:tint="@color/gris_desactivado" />
</LinearLayout>
</LinearLayout>
问题似乎也是一样。当在从属视图中滚动内容(RecyclerView
,NestedScrollView
)小于视图高度时,此行为基本上会从AppBarLayout
中删除滚动标志scroll
。它还覆盖偏移滚动视图,这通常由AppBarLayout.ScrollingViewBehavior
完成。将页脚(即按钮)添加到滚动视图或ViewPager
中时效果良好,其中每个页面的内容长度可能不同
已在中回答要修复底部栏,首先必须使用选项卡所在的活动。在该活动中,使用不同的片段。在此活动\u main\u tab.xml中添加表格布局
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/co_activity_root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<android.support.design.widget.AppBarLayout
local:theme="@style/Theme.AppBarOverlay"
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar_layout">
<FrameLayout
android:id="@+id/fl_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
活动\u main\u tab.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="@+id/co_activity_root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<android.support.design.widget.AppBarLayout
local:theme="@style/Theme.AppBarOverlay"
android:id="@+id/toolbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/toolbar_layout">
<FrameLayout
android:id="@+id/fl_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
ViewPagerAdapter.java
public class ViewPagerAdapter extends FragmentPagerAdapter {
public ViewPagerAdapter(Activity activity, FragmentManager fragmentManager) {
super(fragmentManager);
}
@Override
public Fragment getItem(int position) {
Bundle bundle;
switch (position) {
case 0: // For Tab 1
// use fragment for tab 1
return fragment1;
case 1: // For Tab 2
// use fragment for tab 2
return fragment2;
case 2: // For Tab 3
// use fragment for tab 3
return fragment3;
default:
return null;
}
}
@Override
public int getCount() {
return 3; // no. of Tabs
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0: // Title For Tab1
return "Tab1";
case 1: // Title For Tab2
return "Tab2";
case 2: // Title For Tab3
return "Tab3";
default:
return null;
}
}
}
您可以尝试在工具栏上添加collapseMode,如下所示
你的AppBar布局看起来不错
我建议您查看以下链接:
我也面临同样的问题,这就是我的工作方式
删除AppBarLayout
layout\u行为
,使其固定在顶部。将FrameLayout
layout\u行为定义为app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
以便在appbar布局下调整FrameLayout
。这样,框架布局的内容将滚动,但不会滚动工具栏<代码>坐标布局
布局如下
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.next_tech.teebox.GridView">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:titleTextColor="@android:color/white" />
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
我希望它能帮助别人谢谢
更多信息-
您不能在协调布局中执行此操作。因此,请使用RelativeLayout并在其设计中使用您自己的布局尝试以下布局:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_navigation"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="110dp"
android:padding="15dp"
card_view:cardElevation="2dp"
card_view:cardCornerRadius="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Test" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view1"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="110dp"
android:padding="15dp"
card_view:cardElevation="2dp"
card_view:cardCornerRadius="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Test" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view3"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="110dp"
android:padding="15dp"
card_view:cardElevation="2dp"
card_view:cardCornerRadius="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Test" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view4"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="110dp"
android:padding="15dp"
card_view:cardElevation="2dp"
card_view:cardCornerRadius="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Test" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view5"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="110dp"
android:padding="15dp"
card_view:cardElevation="2dp"
card_view:cardCornerRadius="4dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Test" />
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:gravity="bottom">
<android.support.design.widget.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_weight="1"
android:foregroundGravity="bottom"
android:background="@color/green"
app:itemIconTint="@color/white"
app:itemTextColor="@color/white"
android:id="@+id/bottomnav"
app:menu="@menu/main">
</android.support.design.widget.BottomNavigationView>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
试试这个
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_navigation"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/red"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/colorPrimary"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/red"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/colorPrimary"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/red"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/colorPrimary"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/red"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/colorPrimary"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/red"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/colorPrimary"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/red"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/colorPrimary"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:gravity="bottom">
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomnav"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_weight="1"
android:background="@color/green"
android:foregroundGravity="bottom"
app:itemIconTint="@color/lightWhite"
app:itemTextColor="@color/lightWhite"
app:menu="@menu/menu"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
最好的解决方案是建立这种层次结构
<ConstraintLayout>
<CoordinatorLayout>
<AppBarLayout>
<ToolBar>
<TabLayout>
</AppBarLayout>
<Inlude>
Put the Main Content here.
</Include>
</CoordinatorLayout>
Other Widgets that you want to be placed at a fixed position.
</ConstraintLayout>
将上面的行添加到include的父视图组中
让我们举一个我正在谈论的方法的例子
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context=".activity.Dashboard">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp"
app:layout_constraintBottom_toTopOf="@+id/container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/background"
android:elevation="0dp"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:titleTextColor="#000000" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:tabBackground="@color/background"
app:tabIndicatorColor="@color/colorAccent"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/black"
app:tabTextColor="@color/black" />
</com.google.android.material.appbar.AppBarLayout>
<include
android:id="@+id/include"
layout="@layout/content_main" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<RelativeLayout
android:id="@+id/btSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/_50sdp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btReceive">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fbSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/_30sdp"
android:background="@color/colorAccent"
android:src="@drawable/ic_upload"
app:rippleColor="@color/colorAccent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/fbSend"
android:layout_alignRight="@id/fbSend"
android:layout_alignBottom="@id/fbSend"
android:layout_marginBottom="@dimen/_3sdp"
android:elevation="@dimen/_10sdp"
android:gravity="center"
android:text="SEND"
android:textColor="@color/white"
android:textSize="@dimen/_8sdp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/btReceive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_50sdp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/container"
app:layout_constraintEnd_toStartOf="@+id/btSend"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fbReceive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/_30sdp"
android:background="@color/colorAccent"
android:src="@drawable/ic_download"
app:rippleColor="@color/colorAccent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/fbReceive"
android:layout_alignRight="@id/fbReceive"
android:layout_alignBottom="@id/fbReceive"
android:layout_marginBottom="@dimen/_3sdp"
android:elevation="@dimen/_10sdp"
android:gravity="center"
android:text="RECEIVE"
android:textColor="@color/white"
android:textSize="@dimen/_8sdp" />
</RelativeLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_7sdp"
android:background="@drawable/bottom_bar_corner"
android:padding="@dimen/_5sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:layout_width="@dimen/_24sdp"
android:layout_height="@dimen/_24sdp"
android:background="@drawable/ic_upload_download"
android:minHeight="0dp"
android:paddingTop="@dimen/_6sdp"
android:paddingBottom="@dimen/_6sdp"
android:textSize="@dimen/_13sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
你能帮我一个忙,告诉我们你是如何隐藏底部栏的吗?我似乎不明白。。。(我不需要顶部栏,只需要底部栏)嗨,汉佐,你找到这个问题的解决方案了吗?你能发布包含CoordinatorLayout
的xml文件吗?你的底部栏需要在CoordinatorLayout级别,并带有底部重力,否则它将与其余内容一起滚动。难道你不能使用RecyclerView实现你的片段布局吗?对于未来的读者,现代Android应用程序中严重不推荐RelativeLayout。你知道,CoordinatorLayout不允许孩子使用gravity
,因此它不会工作BottomNavigationView与ScrollView重叠。需要预期的利润。
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/bottom_navigation"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/red"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/colorPrimary"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/red"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/colorPrimary"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/red"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/colorPrimary"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/red"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/colorPrimary"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/red"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/colorPrimary"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/red"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="50dp"
android:padding="15dp"
app:cardBackgroundColor="@color/colorPrimary"
app:cardCornerRadius="4dp"
app:cardElevation="2dp">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Nilesh Rathod"
android:textColor="#ffFFff" />
</android.support.v7.widget.CardView>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="bottom"
android:gravity="bottom">
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomnav"
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_weight="1"
android:background="@color/green"
android:foregroundGravity="bottom"
app:itemIconTint="@color/lightWhite"
app:itemTextColor="@color/lightWhite"
app:menu="@menu/menu"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
<ConstraintLayout>
<CoordinatorLayout>
<AppBarLayout>
<ToolBar>
<TabLayout>
</AppBarLayout>
<Inlude>
Put the Main Content here.
</Include>
</CoordinatorLayout>
Other Widgets that you want to be placed at a fixed position.
</ConstraintLayout>
app:layout_behavior="@string/appbar_scrolling_view_behavior"
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@id/container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:context=".activity.Dashboard">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
app:elevation="0dp"
app:layout_constraintBottom_toTopOf="@+id/container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/background"
android:elevation="0dp"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/AppTheme.PopupOverlay"
app:titleTextColor="#000000" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:tabBackground="@color/background"
app:tabIndicatorColor="@color/colorAccent"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/black"
app:tabTextColor="@color/black" />
</com.google.android.material.appbar.AppBarLayout>
<include
android:id="@+id/include"
layout="@layout/content_main" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<RelativeLayout
android:id="@+id/btSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/_50sdp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/container"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btReceive">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fbSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/_30sdp"
android:background="@color/colorAccent"
android:src="@drawable/ic_upload"
app:rippleColor="@color/colorAccent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/fbSend"
android:layout_alignRight="@id/fbSend"
android:layout_alignBottom="@id/fbSend"
android:layout_marginBottom="@dimen/_3sdp"
android:elevation="@dimen/_10sdp"
android:gravity="center"
android:text="SEND"
android:textColor="@color/white"
android:textSize="@dimen/_8sdp" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/btReceive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/_50sdp"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@id/container"
app:layout_constraintEnd_toStartOf="@+id/btSend"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fbReceive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/_30sdp"
android:background="@color/colorAccent"
android:src="@drawable/ic_download"
app:rippleColor="@color/colorAccent" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@id/fbReceive"
android:layout_alignRight="@id/fbReceive"
android:layout_alignBottom="@id/fbReceive"
android:layout_marginBottom="@dimen/_3sdp"
android:elevation="@dimen/_10sdp"
android:gravity="center"
android:text="RECEIVE"
android:textColor="@color/white"
android:textSize="@dimen/_8sdp" />
</RelativeLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/_7sdp"
android:background="@drawable/bottom_bar_corner"
android:padding="@dimen/_5sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:layout_width="@dimen/_24sdp"
android:layout_height="@dimen/_24sdp"
android:background="@drawable/ic_upload_download"
android:minHeight="0dp"
android:paddingTop="@dimen/_6sdp"
android:paddingBottom="@dimen/_6sdp"
android:textSize="@dimen/_13sdp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>