Navigation Drawer not working in Android Studio - android

I'm really confused about how can I implement the navigation sidebar in my app, yet I already tried it but it conflicts and it tears down my design XML if I've implemented it. The conflict is when I change my constraintLayout to DrawLayout under activity_main my design will tear down but when implementing navigation sidebar I need to use DrawLayout instead of ConstraintLayout
Fist Image is the main XML the normal UI , the Second image describes the output when I tried to change my constraintlayout to drawerlayout in my activity main, some design didn't showed up, but the navigation sidebar works well like in the Third image. The question is it is possible to use constraintlayout instead of drawerlayout ? to avoid tearing down the UI design? or maybe there is other way to view the design using drawerLayout.
Activitymain.xml This is what I used in second Image using drawerlayout The navigation sidebar works well in this but the design teared down. but when I used <androidx.constraintlayout.widget.ConstraintLayout constraintlayout the UI layout will not tear down but it conflicts and the app crashed because in the MainActivity it using ActionBarDrawerToggle . I hope anyone can help me with this problem
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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:background="#color/background"
android:id="#+id/drawerlayout"
tools:context=".MainActivity">
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/navigationview"
app:headerLayout="#layout/sidebar_header"
app:menu="#menu/sidemenu"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_gravity="start"/>
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/background"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:title="Toolbars"
app:titleTextColor="#FFFFFF"
app:titleMarginStart = "10dp"
android:layout_marginBottom="5dp"
tools:ignore="MissingConstraints"/>
<View
android:id="#+id/viewHeaderBackground"
android:layout_width="match_parent"
android:layout_height="#dimen/_125sdp"
android:background="#color/primary"
app:layout_constraintTop_toTopOf="parent"/>
<com.github.ybq.android.spinkit.SpinKitView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/spin_kit"
style="#style/SpinKitView.Large.Circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:SpinKit_Color="#color/validation"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/textTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_16sdp"
android:layout_marginLeft="#dimen/_16sdp"
android:layout_marginTop="#dimen/_16sdp"
android:text="Cash Grants"
android:textColor="#color/white"
android:textSize="#dimen/_20ssp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="#dimen/_26sdp"
android:layout_height="#dimen/_26sdp"
android:layout_marginEnd="#dimen/_16sdp"
android:layout_marginRight="#dimen/_16sdp"
android:src="#drawable/dswd_logo"
app:layout_constraintBottom_toBottomOf="#id/textTitle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#id/textTitle"
app:tint="#color/white"
/>
<com.google.android.material.card.MaterialCardView
android:id="#+id/cardHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_16sdp"
android:layout_marginEnd="#dimen/_16sdp"
app:cardBackgroundColor="#color/card_background"
app:cardCornerRadius="#dimen/_16sdp"
app:layout_constraintBottom_toBottomOf="#id/viewHeaderBackground"
app:layout_constraintTop_toBottomOf="#id/viewHeaderBackground">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/_14sdp">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Overview"
android:textColor="#color/primary_text"
android:textSize="#dimen/_14ssp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ImageButton
android:id="#+id/textViews"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:id="#+id/layoutClients"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_8sdp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toStartOf="#id/layoutImpacted"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/textViews">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="#dimen/_28sdp"
android:layout_height="#dimen/_28sdp"
android:src="#drawable/ic_clients"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="Sync"
android:textColor="#color/secondary_text"
android:textSize="#dimen/_10ssp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="0"
android:textColor="#color/primary_text"
android:textSize="#dimen/_16ssp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layoutImpacted"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_8sdp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toStartOf="#id/layoutFollowing"
app:layout_constraintStart_toEndOf="#id/layoutClients"
app:layout_constraintTop_toBottomOf="#id/textViews">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="#dimen/_28sdp"
android:layout_height="#dimen/_28sdp"
android:src="#drawable/ic_impacted"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="Pending"
android:textColor="#color/secondary_text"
android:textSize="#dimen/_10ssp"/>
<TextView
android:id="#+id/txtPending"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="0"
android:textColor="#color/primary_text"
android:textSize="#dimen/_16ssp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layoutFollowing"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_8sdp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/layoutImpacted"
app:layout_constraintTop_toBottomOf="#id/textViews">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="#dimen/_28sdp"
android:layout_height="#dimen/_28sdp"
android:src="#drawable/ic_following"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="Spam"
android:textColor="#color/secondary_text"
android:textSize="#dimen/_10ssp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="0"
android:textColor="#color/primary_text"
android:textSize="#dimen/_16ssp"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="false"
android:overScrollMode="never"
android:padding="#dimen/_16sdp"
android:scrollbars="none"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#id/cardHeader">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="#layout/dashboard_item_1"/>
<include layout="#layout/dashboard_item_2"/>
<include layout="#layout/dashboard_item_3"/>
<include layout="#layout/dashboard_item_4"/>
</LinearLayout>
</ScrollView>
</androidx.drawerlayout.widget.DrawerLayout >
MainActivity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawerlayout = findViewById(R.id.drawerlayout);
navigationView = findViewById(R.id.navigationview);
toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this,drawerlayout,toolbar,R.string.navigation_open,R.string.navigation_close);
drawerlayout.addDrawerListener(toggle);
toggle.syncState();

The question is it is possible to use constraintlayout instead of drawerlayout
Yes it is.
You just need to make sure that your design skeleton looks like:
<DrawerLayout>
<NavigationView>
<!--Main layout-->
<ConstraintLayout>
<view1 inside ConstraintLayout>
<view2 inside ConstraintLayout>
....
But what you did is that you replaced the ConstraintLayout with DrawerLayout so that the views could't be properly laid out with the unknown constraints:
<DrawerLayout>
<NavigationView>
<view1 inside ConstraintLayout>
<view2 inside ConstraintLayout>
....
So, applying that in your layout:
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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:background="#color/background"
android:id="#+id/drawerlayout"
tools:context=".MainActivity">
<com.google.android.material.navigation.NavigationView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/navigationview"
app:headerLayout="#layout/sidebar_header"
app:menu="#menu/sidemenu"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_gravity="start"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/background"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:title="Toolbars"
app:titleTextColor="#FFFFFF"
app:titleMarginStart = "10dp"
android:layout_marginBottom="5dp"
tools:ignore="MissingConstraints"/>
<View
android:id="#+id/viewHeaderBackground"
android:layout_width="match_parent"
android:layout_height="#dimen/_125sdp"
android:background="#color/primary"
app:layout_constraintTop_toTopOf="parent"/>
<com.github.ybq.android.spinkit.SpinKitView
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/spin_kit"
style="#style/SpinKitView.Large.Circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:SpinKit_Color="#color/validation"
tools:ignore="MissingConstraints" />
<TextView
android:id="#+id/textTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_16sdp"
android:layout_marginLeft="#dimen/_16sdp"
android:layout_marginTop="#dimen/_16sdp"
android:text="Cash Grants"
android:textColor="#color/white"
android:textSize="#dimen/_20ssp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="#dimen/_26sdp"
android:layout_height="#dimen/_26sdp"
android:layout_marginEnd="#dimen/_16sdp"
android:layout_marginRight="#dimen/_16sdp"
android:src="#drawable/dswd_logo"
app:layout_constraintBottom_toBottomOf="#id/textTitle"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="#id/textTitle"
app:tint="#color/white"
/>
<com.google.android.material.card.MaterialCardView
android:id="#+id/cardHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_16sdp"
android:layout_marginEnd="#dimen/_16sdp"
app:cardBackgroundColor="#color/card_background"
app:cardCornerRadius="#dimen/_16sdp"
app:layout_constraintBottom_toBottomOf="#id/viewHeaderBackground"
app:layout_constraintTop_toBottomOf="#id/viewHeaderBackground">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="#dimen/_14sdp">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Overview"
android:textColor="#color/primary_text"
android:textSize="#dimen/_14ssp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<ImageButton
android:id="#+id/textViews"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<LinearLayout
android:id="#+id/layoutClients"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_8sdp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toStartOf="#id/layoutImpacted"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/textViews">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="#dimen/_28sdp"
android:layout_height="#dimen/_28sdp"
android:src="#drawable/ic_clients"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="Sync"
android:textColor="#color/secondary_text"
android:textSize="#dimen/_10ssp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="0"
android:textColor="#color/primary_text"
android:textSize="#dimen/_16ssp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layoutImpacted"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_8sdp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toStartOf="#id/layoutFollowing"
app:layout_constraintStart_toEndOf="#id/layoutClients"
app:layout_constraintTop_toBottomOf="#id/textViews">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="#dimen/_28sdp"
android:layout_height="#dimen/_28sdp"
android:src="#drawable/ic_impacted"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="Pending"
android:textColor="#color/secondary_text"
android:textSize="#dimen/_10ssp"/>
<TextView
android:id="#+id/txtPending"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="0"
android:textColor="#color/primary_text"
android:textSize="#dimen/_16ssp"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layoutFollowing"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_8sdp"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/layoutImpacted"
app:layout_constraintTop_toBottomOf="#id/textViews">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="#dimen/_28sdp"
android:layout_height="#dimen/_28sdp"
android:src="#drawable/ic_following"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="Spam"
android:textColor="#color/secondary_text"
android:textSize="#dimen/_10ssp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/_4sdp"
android:text="0"
android:textColor="#color/primary_text"
android:textSize="#dimen/_16ssp"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:clipToPadding="false"
android:overScrollMode="never"
android:padding="#dimen/_16sdp"
android:scrollbars="none"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="#id/cardHeader">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="#layout/dashboard_item_1"/>
<include layout="#layout/dashboard_item_2"/>
<include layout="#layout/dashboard_item_3"/>
<include layout="#layout/dashboard_item_4"/>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.drawerlayout.widget.DrawerLayout >

Related

Android: Can't move the Keyboard accessible control to the Include Tag Layout

I am not able to access the contents of include layout from Bluetooth Keyboard.
In my scenario there are 2 layouts:
One is for the toolbar which is kept under include Tag and
Other is a simple scrollview layout.
I have tried by providing android:nextFocusUp="#id/include_toolbar" to my scrollview layout but the control is not navigating to the contents of include tag.
Here is my code
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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:background="#android:color/white"
android:fitsSystemWindows="true">
<include
android:id="#+id/include_toolbar"
layout="#layout/toolbar_second_level" />
<ScrollView
android:id="#+id/sv_menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:nextFocusUp="#id/include_toolbar"
android:fillViewport="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="#+id/rl_menu_pt_container"
android:layout_width="match_parent"
android:layout_height="#dimen/size_50dp"
android:layout_marginTop="#dimen/size_20dp"
android:layout_marginBottom="#dimen/size_5dp"
android:background="#drawable/selector_menu"
android:clickable="true"
android:focusable="true">
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/iv_menu_pt_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="#dimen/size_16dp"
android:src="#drawable/selector_menu_pt" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tv_menu_pt_label"
style="#style/TextAppearance.AppCompat.Menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="#dimen/size_16dp"
android:layout_toStartOf="#id/tv_menu_pt_count_container"
android:layout_toEndOf="#id/iv_menu_pt_icon"
android:fontFamily="#font/roboto_medium"
android:text="#string/menu_pt"
android:textColor="#color/gray1" />
<RelativeLayout
android:id="#+id/tv_menu_pt_count_container"
android:layout_width="wrap_content"
android:layout_height="#dimen/size_30dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/size_16dp"
android:background="#drawable/bg_menu_count"
android:minWidth="#dimen/size_30dp"
android:padding="#dimen/size_5dp">
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tv_menu_pt_count"
style="#style/TextAppearance.AppCompat.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:fontFamily="#font/roboto_medium"
android:textColor="#color/agilepoint_blue" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_menu_wl_container"
android:layout_width="match_parent"
android:layout_height="#dimen/size_50dp"
android:layout_marginBottom="#dimen/size_5dp"
android:background="#drawable/selector_menu"
android:clickable="true"
android:focusable="true">
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/iv_menu_wl_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="#dimen/size_16dp"
android:src="#drawable/selector_menu_watchlist" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tv_menu_wl_label"
style="#style/TextAppearance.AppCompat.Menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="#dimen/size_16dp"
android:layout_toStartOf="#id/tv_menu_wl_count_container"
android:layout_toEndOf="#id/iv_menu_wl_icon"
android:fontFamily="#font/roboto_medium"
android:text="#string/menu_watchlist"
android:textColor="#color/gray1" />
<RelativeLayout
android:id="#+id/tv_menu_wl_count_container"
android:layout_width="wrap_content"
android:layout_height="#dimen/size_30dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/size_16dp"
android:background="#drawable/bg_menu_count"
android:minWidth="#dimen/size_30dp"
android:padding="#dimen/size_5dp">
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tv_menu_wl_count"
style="#style/TextAppearance.AppCompat.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:fontFamily="#font/roboto_medium"
android:textColor="#color/blue" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_menu_ps_container"
android:layout_width="match_parent"
android:layout_height="#dimen/size_50dp"
android:layout_marginBottom="#dimen/size_5dp"
android:background="#drawable/selector_menu"
android:clickable="true"
android:focusable="true">
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/iv_menu_ps_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="#dimen/size_16dp"
android:src="#drawable/selector_menu_processes" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tv_menu_ps_label"
style="#style/TextAppearance.AppCompat.Menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="#dimen/size_16dp"
android:layout_toStartOf="#id/tv_menu_ps_count_container"
android:layout_toEndOf="#id/iv_menu_ps_icon"
android:fontFamily="#font/roboto_medium"
android:text="#string/menu_ps"
android:textColor="#color/gray1" />
<RelativeLayout
android:id="#+id/tv_menu_ps_count_container"
android:layout_width="wrap_content"
android:layout_height="#dimen/size_30dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/size_16dp"
android:background="#drawable/bg_menu_count"
android:minWidth="#dimen/size_30dp"
android:padding="#dimen/size_5dp">
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tv_menu_ps_count"
style="#style/TextAppearance.AppCompat.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:fontFamily="#font/roboto_medium"
android:textColor="#color/blue" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_menu_pw_container"
android:layout_width="match_parent"
android:layout_height="#dimen/size_50dp"
android:layout_marginTop="#dimen/size_5dp"
android:layout_marginBottom="#dimen/size_5dp"
android:background="#drawable/selector_menu"
android:clickable="true"
android:focusable="true">
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/iv_menu_pw_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="#dimen/size_16dp"
android:src="#drawable/selector_menu_processes" />
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tv_menu_pw_label"
style="#style/TextAppearance.AppCompat.Menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="#dimen/size_16dp"
android:layout_toStartOf="#id/rl_menu_pw_count_container"
android:layout_toEndOf="#id/iv_menu_pw_icon"
android:fontFamily="#font/roboto_medium"
android:text="#string/menu_pw"
android:textColor="#color/gray1" />
<RelativeLayout
android:id="#+id/rl_menu_pw_count_container"
android:layout_width="wrap_content"
android:layout_height="#dimen/size_30dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/size_16dp"
android:background="#drawable/bg_menu_count"
android:minWidth="#dimen/size_30dp"
android:padding="#dimen/size_5dp">
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tv_menu_pw_count"
style="#style/TextAppearance.AppCompat.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:fontFamily="#font/roboto_medium"
android:textColor="#color/blue" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Code for toolbar_second_level.xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/app_bar_layout_second_level"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#android:color/white"
android:descendantFocusability="afterDescendants"
android:focusableInTouchMode="true"
app:elevation="#dimen/size_0dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_toolbar_menu_back"
android:layout_width="#dimen/size_50dp"
android:layout_height="match_parent"
android:clickable="true"
android:contentDescription="#string/cl_toolbar_menu_back"
android:focusedByDefault="false"
android:nextFocusRight="#id/app_bar_toolbar_second_level">
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:background="#drawable/ic_back_menu"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.appbar.MaterialToolbar
android:id="#+id/app_bar_toolbar_second_level"
style="#style/TextAppearance.AppCompat.Medium"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_toStartOf="#id/cl_toolbar_menu_settings"
android:layout_toEndOf="#id/cl_toolbar_menu_back"
android:background="#android:color/white"
android:focusable="true"
android:focusedByDefault="true"
android:nextFocusRight="#id/cl_toolbar_menu_settings"
app:contentInsetLeft="#dimen/size_0dp"
app:contentInsetStart="#dimen/size_0dp"
app:contentInsetStartWithNavigation="#dimen/size_0dp"
app:elevation="#dimen/size_0dp"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:popupTheme="#style/AppTheme.NoActionBar"
app:titleCentered="false" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="#+id/cl_toolbar_menu_settings"
android:layout_width="#dimen/size_50dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:contentDescription="#string/cl_toolbar_menu_settings"
android:focusable="true"
android:focusedByDefault="true">
<androidx.appcompat.widget.AppCompatTextView
android:id="#+id/tv_toolbar_menu_settings"
android:layout_width="#dimen/size_25dp"
android:layout_height="#dimen/size_25dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:background="#drawable/ic_settings"
android:padding="#dimen/size_10dp"
android:visibility="gone"
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.appcompat.widget.AppCompatTextView
android:id="#+id/tv_toolbar_menu_save"
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="#dimen/size_6dp"
android:fontFamily="#font/roboto_medium"
android:gravity="center"
android:padding="#dimen/size_10dp"
android:text="#string/save"
android:textColor="#color/blue"
android:textSize="#dimen/text_16"
android:visibility="invisible" />
</RelativeLayout>
</com.google.android.material.appbar.AppBarLayout>
Can anyone suggests me why the control is not getting navigated from the External Keyboard.
Thanks in advance

custom floating action button hidden behind toolbar

I want to display a custom floating action button on top left corner of screen. There is Extended floating action button but it doesn't serve my purpose because i want a button with two images, one back icon and another activity image icon. So to achieve this look i used a custom cardview. But the problem is the button is hidden behind toolbar. How to bring it forward, i used elevation doesn't seem to be working.
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.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"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="#dimen/height_toolbar"
android:background="#drawable/background_small"
app:popupTheme="#style/AppTheme.PopupOverlay">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/nav_button_image"
android:orientation="horizontal"
android:paddingBottom="5dp">
<!-- toolbar counter 1-->
<LinearLayout
android:id="#+id/linearLayout_app_bar_toolbar_plants"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="#id/linearLayout_app_bar_toolbar_to_do"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/plants"
android:textAllCaps="true"
android:textColor="#color/bg_color"
android:textSize="#dimen/text_size_textView_actionbar" />
<TextView
android:id="#+id/plant_count_appbar_main"
android:layout_width="wrap_content"
android:layout_height="#dimen/textView_size_actionbar"
android:layout_gravity="center"
android:text="0/0"
android:textAlignment="center"
android:textColor="#color/bg_color"
android:textSize="#dimen/text_size_textView_actionbar"
android:textStyle="bold" />
</LinearLayout>
<!-- toolbar counter 2-->
<LinearLayout
android:id="#+id/linearLayout_app_bar_toolbar_to_do"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#id/linearLayout_app_bar_toolbar_warnings"
app:layout_constraintStart_toEndOf="#id/linearLayout_app_bar_toolbar_plants"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/to_do"
android:textAllCaps="true"
android:textColor="#color/bg_color"
android:textSize="#dimen/text_size_textView_actionbar" />
<TextView
android:id="#+id/todo_count_appbar_main"
android:layout_width="wrap_content"
android:layout_height="#dimen/textView_size_actionbar"
android:layout_gravity="center"
android:text="0/0"
android:textAlignment="center"
android:textColor="#color/bg_color"
android:textSize="#dimen/text_size_textView_actionbar"
android:textStyle="bold" />
</LinearLayout>
<!-- toolbar counter 3-->
<LinearLayout
android:id="#+id/linearLayout_app_bar_toolbar_warnings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/linearLayout_app_bar_toolbar_to_do"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/warnings"
android:textAllCaps="true"
android:textColor="#color/bg_color"
android:textSize="#dimen/text_size_textView_actionbar" />
<TextView
android:id="#+id/warning_count_appbar_main"
android:layout_width="#dimen/textView_size_actionbar"
android:layout_height="#dimen/textView_size_actionbar"
android:layout_gravity="center"
android:background="#drawable/red_circle"
android:text="0"
android:textAlignment="center"
android:textColor="#color/bg_color"
android:textSize="#dimen/text_size_textView_actionbar"
android:textStyle="bold" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="#dimen/height_imageView_actionbar_logo"
android:layout_alignParentBottom="true"
android:scaleType="fitStart"
android:src="#drawable/gardify_logo_header" />
</RelativeLayout>
</LinearLayout>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<include layout="#layout/content_main" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
android:layout_gravity="right"/>
<androidx.cardview.widget.CardView
android:layout_width="wrap_content"
app:cardBackgroundColor="#color/colorPrimary"
android:elevation="10dp"
android:layout_marginTop="80dp"
app:cardCornerRadius="0dp"
app:popupTheme="#style/AppTheme.AppBarOverlay"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/margin_padding_size_small"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginRight="10dp"
android:src="#drawable/ic_back_arrow" />
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/gardify_app_icon_to_do_kalender" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Try using
app:elevation
instead of
android:elevation
Then set the elevation for cardview greater than the appbar/toolbar.
Try to move the <CardView /> element above the <AppBarLayout /> element

Using Constraint layout not able to place a textview below guideline

I am trying to place a TextView below Guideline. I have tried as below,
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/package_name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="20sp"
android:text="Package Name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="#id/start_guideline"
/>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/start_guideline"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content"
app:layout_constraintGuide_percent="0.05"/>
<TextView
android:id="#+id/sub_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subscription"
android:textColor="#color/black"
android:textSize="15sp"
app:layout_constraintTop_toBottomOf="#id/package_name_text_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
My Package name TextView is not displaying below Guideline...I am new to use ConstraintLayout. Not able to find my mistake...Anybody help me to solve this.
Remove constraintTop_toTopOf in package_name_text_view
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/package_name_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/black"
android:textSize="20sp"
android:text="Package Name"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="#id/start_guideline"
/>
<androidx.constraintlayout.widget.Guideline
android:id="#+id/start_guideline"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content"
app:layout_constraintGuide_percent="0.05"/>
<TextView
android:id="#+id/sub_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subscription"
android:textColor="#color/black"
android:textSize="15sp"
app:layout_constraintTop_toBottomOf="#id/package_name_text_view"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

Top_toBottomof is not working in constraintlayout . How to use Top_toBottomof in Constraint layout?

I have this following layout:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar_with_filter_back" />
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/banner"
app:layout_constraintTop_toTopOf="parent"
tools:layout_editor_absoluteX="0dp" />
<android.support.constraint.Guideline
android:id="#+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_begin="165dp" />
<android.support.v7.widget.CardView
android:id="#+id/win_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_5sdp"
android:elevation="#dimen/_8sdp"
app:cardCornerRadius="#dimen/_10sdp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
app:layout_constraintTop_toBottomOf="#+id/guideline">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="#dimen/_10sdp">
<android.support.v7.widget.CardView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.4"
android:gravity="center"
android:scaleType="fitXY"
app:cardCornerRadius="8dp"
app:cardPreventCornerOverlap="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/exec_business_icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center"
android:scaleType="fitXY"
android:src="#drawable/icon_dairy" />
<TextView
android:id="#+id/exec_business_iconname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/exec_card_second_title"
android:fontFamily="#font/boutrosasma_regular"
android:gravity="center"
android:text="Foods"
android:textColor="#color/white"
android:textSize="#dimen/text_size_h" />
</RelativeLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="#+id/tvRname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:fontFamily="#font/boutrosasma_bold"
android:gravity="center"
android:text="#string/exe_size"
android:textColor="#color/exec_card_second_title"
android:textSize="#dimen/text_size_h_valve"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/fb_sr_bu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:fontFamily="#font/boutrosasma_regular"
android:gravity="center"
android:text="SR"
android:textColor="#color/exec_card_size_val_color"
android:textSize="#dimen/text_size_h"
android:textStyle="bold" />
<TextView
android:id="#+id/fb_size_val_bu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="#dimen/_5sdp"
android:ellipsize="end"
android:fontFamily="#font/boutrosasma_bold"
android:gravity="center"
android:text="56.9"
android:textColor="#color/exec_card_size_val_color"
android:textSize="#dimen/_14ssp"
android:textStyle="bold" />
<TextView
android:id="#+id/fb_bn_bu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:fontFamily="#font/boutrosasma_regular"
android:gravity="center"
android:text="BN"
android:layout_marginLeft="#dimen/_5sdp"
android:textColor="#color/exec_card_size_val_color"
android:textSize="#dimen/text_size_h"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:src="#drawable/layer_5" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center">
<TextView
android:id="#+id/tvgrowth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:fontFamily="#font/boutrosasma_bold"
android:gravity="center"
android:text="#string/exe_growth"
android:textColor="#color/exec_card_second_title"
android:textSize="#dimen/text_size_h_valve"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="#+id/fb_growth_bu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:fontFamily="#font/boutrosasma_bold"
android:gravity="center"
android:text="+7.0%"
android:textColor="#color/exec_growth_val_color"
android:textSize="#dimen/_14ssp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="#+id/card_topplayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_5sdp"
android:elevation="#dimen/_8sdp"
app:cardCornerRadius="#dimen/_10sdp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
app:layout_constraintTop_toBottomOf="#+id/win_card"
app:layout_constraintEnd_toEndOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/top_player_back"
android:padding="#dimen/_10sdp">
<TextView
android:id="#+id/top_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/boutrosasma_bold"
android:text="#string/business_unit_top"
android:textColor="#color/exec_card_size_val_color" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:src="#drawable/orientation" />
</RelativeLayout>
<com.github.mikephil.charting.charts.LineChart
android:layout_margin="#dimen/_5sdp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/business_lineChart"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
</LinearLayout>
Problem 1:
When i set the second cardview height to match_parent then it takes the full screen instead of the left screen at the bottom. It means it will override the first cardview also and reach to the top of parent/screen. So in this case why the set constraint toptobottomof is not working and how can i make it work? As far as i know toptobottomof makes sure that your second view will always remain below of first view which in this case is not working.
Problem 2:
If i keep my layout as it is then the problem is the LineChart is not expanding at all. It is compressing the whole chart height into the wrap content height. It is not behaving like it needs more space as this is what wrap_content attribute is made for instead it is restricting the chart itself to that available height and its not expanding the cardview height at all.
Please help me with these issues.
Change height to 0dp of android.support.v7.widget.CardView , width to 0dp
and use app:layout_constraintBottom_toBottomOf="parent"
This will make the height fill to the parent
Add these
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Example
<androidx.cardview.widget.CardView
android:id="#+id/card_topplayer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_margin="#dimen/_5sdp"
android:elevation="#dimen/_8sdp"
app:cardCornerRadius="#dimen/_10sdp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/win_card">
Update
To implement scrollview use fillviewport = true
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:fillViewport = "true"
android:layout_height="0dp">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
And Remove this app:layout_constraintEnd_toEndOf="parent" from second cardview like this
<android.support.v7.widget.CardView
android:id="#+id/card_topplayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_5sdp"
android:elevation="#dimen/_8sdp"
app:cardCornerRadius="#dimen/_10sdp"
app:cardPreventCornerOverlap="false"
app:cardUseCompatPadding="true"
app:layout_constraintTop_toBottomOf="#+id/win_card"
>

How to set height of a view in percent using ConstraintLayout

Currently I'm learning ConstraintLayout
below is my code that i have tried so far
<?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"
android:background="#000000"
android:fitsSystemWindows="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context=".activity.PhaseListActivity">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.8"
android:background="#color/colorAccent">
<VideoView
android:id="#+id/myVideoView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible" />
<TextSwitcher
android:id="#+id/tvAnimText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:fontFamily="#font/knowledge_bold"
android:textColor="#color/greenColor"
android:textSize="#dimen/_100ssp"
android:textStyle="bold"
tools:text="1" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.2"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Scrollbale view below my videoView"
android:textColor="#ff00"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Scrollbale view below my videoView"
android:textColor="#ff00"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Scrollbale view below my videoView"
android:textColor="#ff00"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<LinearLayout
android:id="#+id/bottomView"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="bottom"
android:background="#color/greenColor"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="Fixed Bottombar"
android:textColor="#ff00"
android:textStyle="bold" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
I want don't want use nested LinearLayout inside ConstraintLayout
Also in above layout my NestedScrollView is not scrolling
I want to create this type of screen using ConstraintLayout
My expected OUTPUT
I have tried to set Guideline but it didn't work for me, because i don't know how to use Guideline in above layout
Can anybody help me create this screen only using ConstraintLayout
If need more information please do let me know. Thanks in advance. Your efforts will be appreciated.
So, after looking at your xml file, I've come up with solution to get rid of nested LinearLayout hierarchy in below solution:
<?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"
android:background="#000000"
android:fitsSystemWindows="true"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<androidx.core.widget.NestedScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:fillViewport="true"
app:layout_constraintBottom_toTopOf="#id/tv_bottom_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<VideoView
android:id="#+id/myVideoView"
android:layout_width="0dp"
android:layout_height="0dp"
android:visibility="visible"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toTopOf="#id/tv1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent="0.85"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<TextSwitcher
android:id="#+id/tvAnimText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:fontFamily="#font/knowledge_bold"
android:textColor="#color/greenColor"
android:textSize="#dimen/_100ssp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="#id/myVideoView"
app:layout_constraintEnd_toEndOf="#id/myVideoView"
app:layout_constraintStart_toStartOf="#id/myVideoView"
app:layout_constraintTop_toTopOf="#id/myVideoView"
tools:text="1" />
<TextView
android:id="#+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Scrollbale view below my videoView"
android:textColor="#ff00"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#id/tv2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/myVideoView" />
<TextView
android:id="#+id/tv2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Scrollbale view below my videoView"
android:textColor="#ff00"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="#id/tv3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/tv1" />
<TextView
android:id="#+id/tv3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="10dp"
android:text="Scrollbale view below my videoView"
android:textColor="#ff00"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/tv2" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
<TextView
android:id="#+id/tv_bottom_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center"
android:text="Fixed Bottombar"
android:textColor="#ff00"
android:textStyle="bold"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent="0.08"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Let me know if there's any query in comments. For your fixed bottombar TextView, now you can change height percent to whatever you want to change it's height dynamically.
You can use below code for bottom View which remove your Nested LinearLayout :
<TextView
android:id="#+id/bottomView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Fixed Bottombar"
android:textColor="#ff00"
android:background="#00ff00"
android:padding="15dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:textStyle="bold" />

Categories

Resources