Bottomsheet dialog always appear on UI instead of disapear - android

I have a problem when create bottomsheet in android (look likes google maps)
when i come to maps ui,but bottom sheet does not hide
Expectation: Click on marker and appear the bottom sheet likes google maps
Here is my 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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.dangquang.stackexchange.activity.MapActivity">
<android.support.v7.widget.Toolbar
android:id="#+id/actMap_Toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:titleTextColor="#android:color/white">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/title_maps"
android:textSize="#dimen/title_nav_toolbar" />
</android.support.v7.widget.Toolbar>
<android.support.v7.widget.Toolbar
android:id="#+id/actMap_tbDetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:visibility="gone">
<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">
<TextView
android:id="#+id/actMap_tvDuration"
style="#style/title_detail_direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="#drawable/duration_icon" />
<TextView
android:id="#+id/actMap_tvDistance"
style="#style/title_detail_direction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableRight="#drawable/distance_icon" />
<Spinner
android:id="#+id/actMap_spnMode"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:id="#+id/actMap_tvDirection"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="#dimen/_5sdp"
android:textColor="#android:color/white"
android:textSize="#dimen/_14sdp" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
<EditText
android:id="#+id/actMap_etSearch"
style="#style/action_searchMap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/place_autocomplete_search_hint"
android:imeOptions="actionSearch"
android:inputType="text" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/actMap_frgMaps"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
>
<android.support.v4.widget.NestedScrollView
android:id="#+id/actMap_BottomSheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/actMap_tvDetailName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="#dimen/item_title_size"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/actMap_tvDetailPoint"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1" />
<TextView
android:id="#+id/actMap_tvDetailDuration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="#drawable/car_icon"
style="#style/navigation_item_text" />
</LinearLayout>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
</FrameLayout>
</LinearLayout>

You can set bottomsheet invisible on onCreate with this actMap_BottomSheet.setVisibility(View.INVISIBLE) and make it visible whenever you want.
But your xml is so complex and has so many nested levels which causes to performance issues. I suggest you to use constraint layout.

Related

How To Hide AppBar When Scrolling Down

I have an AppBar and other things in my layout. When the user scrolls down, I want AppBar(actually, the Toolbar to hide. This is what I have tried, the app bar isn't hiding all small part it just stays there. Actually I think the problem is with my header of the screen it gets collapsed and adds a small space when I scroll.
As you can see in second image some part stays it doesn't hide. I need to hide that part while scrolling.
Please provide me solution what am I doing wrong?
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleTextAppearance="#style/TextAppearance.AppCompat.Title"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:titleEnabled="false">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/slideIV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_dish" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/bottomButtonRL"
android:layout_gravity="bottom"
android:background="#drawable/gradient_bg" />
<View style="#style/itemBottomViewLarge" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_margin="#dimen/_20"
android:gravity="center_vertical"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="80dp"
android:layout_height="80dp"
android:src="#drawable/fake_chef_bg"
app:civ_border_color="#color/border_grey_color"
app:civ_border_width="#dimen/_2" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="#dimen/_5"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/bold_font"
android:text="#string/fatima_al_zahraa"
android:textColor="#color/white"
android:textSize="#dimen/large_text_size"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="#font/regular_font"
android:text="#string/presenter_of_the_cuient"
android:textColor="#color/white"
android:textSize="#dimen/app_text_size" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/bottomButtonRL"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/slideIV"
android:layout_marginTop="-25dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="#dimen/_0"
android:layout_weight="1" />
<View
android:layout_width="match_parent"
android:layout_height="#dimen/_0"
android:layout_weight="1"
android:background="#color/defaultColor" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="#dimen/_20"
android:paddingLeft="#dimen/_20">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_share" />
<RelativeLayout
android:layout_width="220dp"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/_10"
android:layout_marginLeft="#dimen/_10"
android:background="#drawable/ic_rec1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="#font/regular_font"
android:gravity="center"
android:layout_centerInParent="true"
android:text="#string/add_to_fav"
android:textColor="#color/white"
android:textSize="#dimen/medium_text_size" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bottom_radius_view">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/regular_font"
android:padding="#dimen/_20"
android:text="#string/galetes_fires_au_plates_fires_au_plates_fires_au_plates_fires_au_plates_fires_au_plates"
android:textColor="#color/white"
android:textSize="#dimen/app_text_size" />
</LinearLayout>
</LinearLayout>
<androidx.appcompat.widget.Toolbar
android:visibility="gone"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light"
/>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="#dimen/_20"
android:paddingTop="#dimen/_10"
android:paddingRight="#dimen/_20">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="#font/bold_font"
android:padding="#dimen/_5"
android:text="#string/les_videos"
android:textColor="#color/medium_grey_text_color"
android:textSize="#dimen/large_text_size" />
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/itemFRV"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="#dimen/_5" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
This is the header code:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="#dimen/header_height"
android:background="#color/white"
android:gravity="center"
android:orientation="horizontal"
android:paddingLeft="#dimen/_20"
android:paddingRight="#dimen/_20">
<LinearLayout
android:id="#+id/backLL"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:gravity="center"
android:paddingRight="#dimen/_20"
android:layout_marginBottom="#dimen/_10"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/ic_back" />
</LinearLayout>
<ImageView
android:id="#+id/logoIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:adjustViewBounds="true"
android:paddingStart="0dp"
android:paddingTop="#dimen/_15"
android:paddingEnd="#dimen/_10"
android:layout_marginBottom="#dimen/_10"
android:src="#drawable/ic_header_logo" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<ImageView
android:id="#+id/profileIV"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:adjustViewBounds="true"
android:paddingStart="#dimen/_10"
android:paddingTop="#dimen/_15"
android:paddingEnd="0dp"
android:layout_marginBottom="#dimen/_10"
android:src="#drawable/ic_default_user" />
</LinearLayout>
</layout>
Answer to the problem is just remove
android:fitsSystemWindows="true"
Change the layout_scrollFlags
app:layout_scrollFlags="scroll|exitUntilCollapsed"
replace above line with
app:layout_scrollFlags="scroll|enterAlways|enterAlwaysCollapsed"

Aligning multiple views in custom toolbar

I have multiple views (2 Imagebuttons and a Button) supposed to be put properly on my custom toolbar. But the output shows only the first view.
Here is my XML for custom toolbar:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/white"
app:titleTextColor="#color/colorPrimaryDark">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top|center"
android:orientation="horizontal"
android:paddingTop="8dp">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingTop="7dp"
android:orientation="horizontal"
android:gravity="left">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:paddingBottom="3dp"
android:gravity="left">
<ImageView
android:id="#+id/tool_bar_backbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logo1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="40dp"
android:paddingRight="10dp"
android:layout_weight="1"
android:background="#android:color/white"
android:gravity="center"
android:orientation="horizontal">
<ImageButton
android:id="#+id/action_sos_toolbar"
android:background="#android:color/white"
android:layout_width="100dp"
android:layout_height="40dp"
android:onClick="sosClick"
android:scaleType="fitCenter"
android:src="#drawable/sos_button_copy" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="1"
android:background="#android:color/white"
android:gravity="right"
android:orientation="horizontal">
<Button
android:id="#+id/action_feedback_toolbar"
android:background="#android:color/white"
android:layout_width="100dp"
android:layout_height="40dp"
android:onClick="feedbackClick"
/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
Only 'logo1' is getting displayed.
I am supposed to put 'logo1' in the left, 'action_sos_toolbar' in the centre and 'action_feedback_toolbar' in the right of the toolbar.
Please help!
Thanks!!!
I can see multiple issues in this layout like empty linear layout and setting "0dp" for layout width etc. Just try like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/white"
app:titleTextColor="#color/colorPrimaryDark">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="8dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:gravity="left"
android:layout_gravity="left">
<ImageView
android:id="#+id/tool_bar_backbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/logo1"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal"
android:layout_gravity="center_horizontal">
<ImageButton
android:id="#+id/action_sos_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="sosClick"
android:src="#drawable/sos_button_copy" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="horizontal"
android:layout_gravity="right">
<Button
android:id="#+id/action_feedback_toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="feedbackClick"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
Nested Linear Layouts are bad for performances. You can only do it with using Relative Layout. Below is the way you need to do it.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#FFFFFF"
app:titleTextColor="#color/colorPrimaryDark">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/tool_bar_backbutton"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="15dp"
android:layout_marginLeft="15dp"
android:src="#mipmap/ic_launcher" />
<ImageButton
android:id="#+id/action_sos_toolbar"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_centerHorizontal="true"
android:background="#android:color/white"
android:onClick="sosClick"
android:scaleType="fitCenter"
android:src="#mipmap/ic_launcher" />
<Button
android:id="#+id/action_feedback_toolbar"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="15dp"
android:layout_marginEnd="15dp"
android:text="Test"
android:textColor="#000000"
android:background="#android:color/white"
android:onClick="feedbackClick" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
Below is the SS of above layout.
You can update your layout like this,if further problem please let me know.The solution is using Relative layout you are using too many linear layouts in your layout and that turns into memory leaks.
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/white"
app:titleTextColor="#color/colorPrimaryDark">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="8dp">
<ImageView
android:id="#+id/tool_bar_backbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="#drawable/logo1" />
<ImageButton
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_centerInParent="true"
android:background="#android:color/white"
android:onClick="sosClick"
android:scaleType="fitCenter"
android:src="#drawable/sos_button_copy" />
<Button
android:id="#+id/action_feedback_toolbar"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:background="#android:color/white"
android:onClick="feedbackClick" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>

Layout is behind Navigation bar (out of screen)

I created a Basic-Activity and have the activity_main which includes the content_main. But at the Design-Screen I can see, that the included content_main starts below the toolbar and ends behind the navigationbar. I think that the Included layout is as high as the full screen and not as high as the space between toolbar and the end of screen. What can I do?
Screenshot of Designscreen
Activity_Main
<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"
tools:context="com.htlhl.kellergassen_app.MainActivity"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/KG_orange">
<android.support.v7.widget.AppCompatTextView
android:id="#+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/HomeActivity"
style="#style/Toolbartitle_KG" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<include layout="#layout/content_main" />
</android.support.design.widget.CoordinatorLayout>
Content_Main
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="#drawable/background2"
android:paddingTop="#dimen/activity_vertical_margin"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="com.htlhl.kellergassen_app.MainActivity"
tools:showIn="#layout/activity_main"
android:id="#+id/rl_main">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="false"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:onClick="here">
<ImageView
android:id="#+id/Kellergassenlogo"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="0dp"
android:contentDescription="#string/ButtonKellergasse"
android:onClick="toKellerkatze"
android:src="#drawable/kk_logo" />
<Button
android:id="#+id/btnToKellergasse"
android:layout_width="180dp"
android:layout_height="36dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="12dp"
android:background="#drawable/roundbutton"
android:onClick="toKellerkatze"
android:text="#string/ButtonKellergasse"
android:textColor="#color/white"
android:textSize="15sp" />
<ImageView
android:id="#+id/Routenlogo"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="top|bottom|center_horizontal"
android:layout_marginTop="15dp"
android:contentDescription="#string/ButtonRoute"
android:onClick="toRouten"
android:src="#drawable/routenlogo" />
<Button
android:id="#+id/btnToRouten"
android:layout_width="180dp"
android:layout_height="36dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="12dp"
android:background="#drawable/roundbutton"
android:onClick="toRouten"
android:text="#string/ButtonRoute"
android:textColor="#color/white"
android:textSize="15sp" />
</LinearLayout>
<Button
android:id="#+id/btnParse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="parse"
android:textColor="#color/black"
android:background="#color/KG_green"
android:onClick="startParsing"/>
<LinearLayout
android:id="#+id/layout_bottom_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
android:layout_weight="2"
android:gravity="center"
android:orientation="vertical">
<fragment
android:id="#+id/fragmentChooseLang"
android:name="com.htlhl.kellergassen_app.FragmentLanguage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/tvChooseLang"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:drawableTop="#drawable/german_flag"
android:text="#string/chooseLanguage"
android:textSize="12sp"
android:textStyle="bold" />
</LinearLayout>
<Button
android:id="#+id/btnToImpressum"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/ButtonImpressum"
android:textSize="15sp"
android:textStyle="bold"
android:layout_gravity="bottom"/>
</LinearLayout>
</RelativeLayout>
The Layout named "layout_bootom_main" is not shown, because it is layout_alignParentBottom and the parents end is out of screen.
You can add scroll view in content_main as parent view for both linear layouts.
<RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="#+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- Add your linear layouts here -->
</LinearLayout>
</ScrollView>
</RelativeLaout>
And while designing in android studio try to preview the design with device having more hight
You could wrap everything inside a scrollview like this:
<RelativeLayout
......>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<-! All the layout children in here-->
</ScrollView>
</RelativeLaout>

Fab gets focus only sometimes

I have a problem testing the focusability of my App with D-pad. Here there are two screenshots of my App:
In the picture of the left side, the fab is "outside(or below)" the list and after the last element it gets the focus when navigating down, so everything is ok in this case. The problem comes with the image of the right side. The fab is "inside" the listView and for that reason(I think but I'am not sure) it doesn't get ever the focus. Is there anything that can be done about it?
An enhacement would be that the fab would get the focus always before the list(that is immediately after the tabs), no matter where the fab is positioned at the momment in the layout, but the problem is that I don't know how to do it, since Android decides the focus order of my Layout.
Any help would be highly appreciated.
UPDATE:
fragment_main.xml
<?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:mContext=".FragmentMain">
<!---marginBottom for ads-->
<android.support.v4.view.ViewPager
android:id="#+id/viewpagerMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
android:layout_marginBottom="60dp"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
<android.support.design.widget.TabLayout
android:id="#+id/tabsMain"
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_marginTop="50dp"
android:background="?attr/colorPrimary"
app:layout_anchor="#+id/appbar"
app:layout_anchorGravity="bottom"
app:tabGravity="fill"
app:tabIndicatorHeight="5dp"
app:tabMode="fixed"
app:tabPaddingTop="60dp"
app:tabSelectedTextColor="#android:color/white"
app:tabTextAppearance="#style/TabTextAppearance" />
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="330dp"
android:fitsSystemWindows="true"
android:theme="#style/AppTheme.AppBarOverlay">
<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:layout_scrollFlags="scroll|exitUntilCollapsed">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="86dp"
android:background="#color/white"
android:orientation="vertical">
<com.github.mikephil.charting.charts.LineChart
android:id="#+id/chart"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_marginLeft="5dp"/>
<ProgressBar
android:id="#+id/progressBar"
android:background="#drawable/progress"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:visibility="visible"
tools:visibility="visible">
</ProgressBar>
</FrameLayout>
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_collapseMode="pin"
app:popupTheme="#style/AppTheme.PopupOverlay"
/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!-- http://antonioleiva.com/floating-action-button/-->
<android.support.design.widget.FloatingActionButton
android:id="#+id/fabMain"
android:focusable="true"
android:background="#drawable/selector_focusable_fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end|right"
android:layout_marginBottom="60dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:src="#drawable/plus_48"
app:pressedTranslationZ="12dp"
app:rippleColor="#color/colorAccent"/>
<include layout="#layout/ad_bottom_bar"
android:id="#+id/advBottomBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
/>
</android.support.design.widget.CoordinatorLayout>
security_item.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- for statedrawable list to work we need to set background in cardview and
immediate linearlayout. Also set android.clickable in cardview AND
android:duplicateParentState in linearlayout-->
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:background="#drawable/selector_security"
android:clickable="true"
android:nextFocusRight="#+id/overflow"
app:contentPadding="#dimen/si_card_view_content_padding"
android:id="#+id/cardView"
card_view:cardCornerRadius="0dp"
card_view:cardElevation="#dimen/si_card_view_elevation"
card_view:cardUseCompatPadding="true"
>
<LinearLayout
android:id="#+id/linearParent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:nextFocusRight="#+id/overflow"
android:duplicateParentState="true"
android:background="#drawable/selector_security">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#id/ticker"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
tools:text="GOOG" />
<TextView
android:id="#+id/market"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:gravity="start"
tools:text="EQUITY" />
<ImageView
android:id="#+id/overflow"
android:focusable="true"
android:nextFocusLeft="#+id/cardView"
android:nextFocusDown="#+id/cardView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/selector_overflow_mini"
android:tint="#color/gray700"
android:src="#drawable/ic_overflow"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.carlos.capstone.customcomponents.AutoResizeTextView
android:id="#+id/securityName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:textStyle="bold"
tools:text="Alphabet Inc." />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="end"
android:textSize="#dimen/si_label_day"
android:text="Day(max/min)"
tools:text="Day(max/min)" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/price"
android:layout_marginTop="3dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:textSize="#dimen/si_price_text_size"
tools:text="710,89" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.9"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.carlos.capstone.customcomponents.AutoResizeTextView
android:id="#+id/percentChange"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="#dimen/si_percent_margin_top"
android:textSize="#dimen/si_percent_text_size"
android:gravity="end"
tools:text="-110.21%" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="vertical">
<com.carlos.capstone.customcomponents.AutoResizeTextView
android:id="#+id/dayMax"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textColor="#color/gray400"
android:gravity="end"
tools:text="716,49" />
<com.carlos.capstone.customcomponents.AutoResizeTextView
android:id="#+id/dayMin"
android:paddingTop="#dimen/si_min_padding_top"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="end"
android:textColor="#color/gray400"
tools:text="706,02" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
You can create a separate Layout and put your fab there. This will force that part to always be seen.
For example
<LinearLayout>
//list stuff here
<LinearLayout>
//fab stuff
</LinearLayout>
</LinearLayout>

Coordinator Layout with RecyclerView

I am using a CoordinatorLayout with RecyclerView.The app runs fine but my problem is the the view should only scroll as the items in RecyclerView.In my case i have only 3 items but the CordinatorLayout will scroll the RecyclerView till it will snap to the top because of this i am getting the below part as white as the listsize is only 3.
XMl
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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.support.design.widget.AppBarLayout
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="#+id/collapsing_toolbar_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="#android:color/transparent"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView38"
android:layout_alignParentTop="true"
android:padding="20dp"
android:src="#drawable/ic_filter_back" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/rv_event_details"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
app:layout_behavior="#string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#fff"
android:orientation="horizontal"
android:paddingBottom="03dp">
<RelativeLayout
android:id="#+id/rl_tab1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:id="#+id/tab1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="05dp"
android:src="#drawable/ic_create_wedding_admin" />
<TextView
android:id="#+id/tv_tab_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tab1"
android:layout_marginLeft="05dp"
android:layout_marginRight="05dp"
android:gravity="center"
android:text="Admin" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_tab2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:id="#+id/tab2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="05dp"
android:src="#drawable/ic_create_wedding_guests" />
<TextView
android:id="#+id/tv_tab_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/tab2"
android:layout_marginLeft="05dp"
android:layout_marginRight="05dp"
android:gravity="center"
android:text="Guests" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_ed_tab_guests"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:id="#+id/iv_ed_iv_budget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="05dp"
android:src="#drawable/ic_create_wedding_budget" />
<TextView
android:id="#+id/tvbud"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/iv_ed_iv_budget"
android:layout_marginLeft="05dp"
android:layout_marginRight="05dp"
android:gravity="center"
android:text="Budget" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rl_ed_tab_tasks"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1">
<ImageView
android:id="#+id/iv_ed_iv_tasks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:padding="05dp"
android:src="#drawable/ic_create_wedding_tasks" />
<TextView
android:id="#+id/tv_ed_tasks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/iv_ed_iv_tasks"
android:layout_marginLeft="05dp"
android:layout_marginRight="05dp"
android:gravity="center"
android:text="Tasks" />
</RelativeLayout>
</LinearLayout>
What i want is to scroll the view only till the item size.
This issue has already been brought up.
Please check other questions before posting another.
You need to provide a custom behavior to your child layout in the Coordinator Layout.
Check this if it helps:
https://stackoverflow.com/a/33461064/2346980

Categories

Resources