01/10/2018, 00:46

Cho mình hỏi về ButtomBar và Navigator với

Hiện tại mình đang làm một navigator drawer và một bottom nhưng ý của mình là khi bật nav lên nó che luôn cả phần bottom nhưng mình vẫn chưa tìm ra được giải pháp nào các bạn hỗ trợ mình với, mình cảm ơn trước ^^

Larry Pham viết 03:00 ngày 01/10/2018

Do cách bố trí layout của bạn thôi… Root layout sẽ là DrawerLayout bên trong đó gồm hai child layout: FrameLayout và NavigationView(dùng cho navigation drawer).
Muốn attach cái BottomBar vào trong layout FrameLayout thì có thể thay đổi sang RelativeLayout và thêm BottomBar với thuộc tính alignParentBottom=“true” Hoặc sử dụng CoordinatorLayout để đặt vị trí của bottombar luôn ở dưới cùng của layout…

Qu Thành viết 02:59 ngày 01/10/2018

Mình làm vẫn chưa thành công bạn à, bên dứoi là code của mình bạn xem hộ mình với ^^

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:app=“http://schemas.android.com/apk/res-auto”
android:id="@+id/drawer_layout"
android:layout_width=“match_parent”
android:layout_height=“match_parent”>

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="64dp"
            app:expandedTitleMarginStart="48dp"
            app:expandedTitleTextAppearance="@android:color/transparent"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">


            <ImageView
                android:id="@+id/backdrop"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/cover"
                app:layout_collapseMode="parallax" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


        </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

<android.support.design.widget.NavigationView
    android:id="@+id/nvView"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:menu="@menu/menu_nav" />

<RelativeLayout
    android:id="@+id/fl_dashboard_fragmentframe"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <com.roughike.bottombar.BottomBar
        android:id="@+id/buttonBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"></com.roughike.bottombar.BottomBar>
</RelativeLayout>

</android.support.v4.widget.DrawerLayout>

Larry Pham viết 02:54 ngày 01/10/2018

Bạn nên để layout này

<com.roughike.bottombar.BottomBar
    android:id="@+id/buttonBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"></com.roughike.bottombar.BottomBar>
bên dưới thẻ Toolbar ấy là được.. vì đây chính là layout chinh của màn hình bạn muốn dựng bên trong thẻ Coordinator thì nó sẽ được cố định vị trí dưới cùng như hiển thik
Larry Pham viết 02:55 ngày 01/10/2018

Hoặc để BottomBar bên trong coordinatorlayout với thuộc tính layout_gravity=“bottom” là okie…

Larry Pham viết 02:50 ngày 01/10/2018

như này nhé:

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.DrawerLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:id="@+id/drawer_layout"
     android:layout_width="match_parent" 
     android:layout_height="match_parent">
     <android.support.design.widget.CoordinatorLayout
        android:id="@+id/main_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:fitsSystemWindows="true">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsing_toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginEnd="64dp"
                app:expandedTitleMarginStart="48dp"
                app:expandedTitleTextAppearance="@android:color/transparent"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">


                <ImageView
                    android:id="@+id/backdrop"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fitsSystemWindows="true"
                    android:scaleType="centerCrop"
                    android:src="@drawable/cover"
                    app:layout_collapseMode="parallax" />

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

               
            </android.support.design.widget.CollapsingToolbarLayout>
        </android.support.design.widget.AppBarLayout>
         <RelativeLayout
                    android:id="@+id/fl_dashboard_fragmentframe"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="bottom"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior">
                    <com.roughike.bottombar.BottomBar
                        android:id="@+id/buttonBar"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentBottom="true">                
                    </com.roughike.bottombar.BottomBar>
               
        </RelativeLayout>    
    </android.support.design.widget.CoordinatorLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/nvView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:menu="@menu/menu_nav" />
</android.support.v4.widget.DrawerLayout>
Kim viết 02:56 ngày 01/10/2018

Lần sau bạn nên đặt câu hỏi chính xác hơn(BottomNavigationBar). Từ version 25.0.0 thì thư viện appcompat đã hộ trợ và bạn có thể dùng luôn mà không cần thêm thư viện ngoài.

https://blog.riddhimanadib.me/exploring-bottom-navigation-bar-in-android-a02fc4b9eebb#.mobzlcof2

Bài liên quan
0