ActionBar is going up when keyboard is in use - android

Action Bar is going out of the screen when keyboard is in use on Edit text.
I have tried using some parameters of windowSoftInputMode on activity tag in Manifest as adjustresize, adjustPan but none of the above worked.
My xml is
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#ffffff"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".MainActivity">
<include
layout="#layout/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="top"
/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".9"
android:id="#+id/scrollView"
android:paddingBottom="#dimen/margin_toolbar"
android:paddingLeft="#dimen/margin_toolbar"
android:paddingRight="#dimen/margin_toolbar"
android:paddingTop="#dimen/margin_toolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/layout1">
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</ScrollView>
<include
layout="#layout/bottom_chat"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight=".1"
android:layout_gravity="bottom"
/>
</LinearLayout>
I am not able to resolve the problem

Related

How to make SwipeRefreshLayout wrap_content?

How to make SwipeRefreshLayout wrap_content?
Here is my layout
mydialog_fragmet.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
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="wrap_content">
<LinearLayout
android:id="#+id/contentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/appBackgroundColorLight"
android:orientation="vertical"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingTop="16dp"
android:scrollbarSize="2dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbarThumbVertical="#color/colorAccent"
/>
<include layout="#layout/view_add_place_button"/>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
In result LinearLayout id/contentLayout becomes match_parent. Here is screenshot :
But when I use the layout without SwipeRefreshLayout content is wrap_content:
mydialog_fragmet.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/appBlue"
android:orientation="vertical"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/placesRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingTop="16dp"
android:scrollbarSize="2dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbarThumbVertical="#color/colorAccent"
app:maxHeight="300dp"
/>
<include layout="#layout/view_add_place_button"/>
</LinearLayout>
Here is right result:
The solution for this specific behavior is to wrap the view in a parent layout, using a specific dp is only recommended if you want it on that size
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/appBackgroundColorLight"
android:orientation="vertical">
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/contentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/appBackgroundColorLight"
android:orientation="vertical"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingTop="16dp"
android:scrollbarSize="2dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbarThumbVertical="#color/colorAccent"
/>
<include layout="#layout/view_add_place_button"/>
</LinearLayout>
</android.support.v4.widget.SwipeRefreshLayout>
Found solution:
<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="wrap_content"
android:orientation="vertical"
>
<com.example.views.MaxHeightSwipeRefreshLayout
android:id="#+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:maxHeight="382dp">//size 382 = 300(RecyclerView) + 82 (addButton)
<com.example.views.MaxHeightNestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:maxHeight="382dp">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/appBackgroundColorLight"
android:orientation="vertical"
tools:background="#color/appBlue"
>
<com.example.views.MaxHeightRecyclerView
android:id="#+id/placesRecyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingTop="16dp"
android:scrollbarSize="2dp"
app:maxHeight="300dp"
android:scrollbarStyle="outsideOverlay"
android:scrollbarThumbVertical="#color/colorAccent"
/>
<include layout="#layout/view_add_place_button"/>
</LinearLayout>
</com.example.views.MaxHeightNestedScrollView>
</com.example.views.MaxHeightSwipeRefreshLayout>
</LinearLayout>
Where MaxHeight* view is from https://stackoverflow.com/a/48728490/2425851

Cannot Fix a header above RecyclerView in Android

I need to show a header above a RecyclerView but with the code below, the header is not fixed and gets scrolled with the recycler view.
Does anyone has a solution for his problem?
fragment_history_detail.xml
[[First Try]]
<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="?android:attr/colorBackground">
<RelativeLayout
android:id="#+id/header_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<include
layout="#layout/view_header_history_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header_container">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_history_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layoutManager="LinearLayoutManager"
tools:listitem="#layout/fragment_history_detail_item_self" />
</RelativeLayout>
</RelativeLayout>
[[Second Try]]
I also tried using LinearLayout like below. But it doesn't help.
<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:background="?android:attr/colorBackground"
android:orientation="vertical">
<include
layout="#layout/view_header_history_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_history_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layoutManager="LinearLayoutManager"
tools:listitem="#layout/fragment_history_detail_item_self" />
</LinearLayout>
[[Third Try]]
<?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:background="?android:attr/colorBackground"
android:orientation="vertical">
<include
layout="#layout/view_header_history_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout 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="?android:attr/colorBackground">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_history_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layoutManager="LinearLayoutManager"
tools:listitem="#layout/fragment_history_detail_item_self" />
</RelativeLayout>
</LinearLayout>
view_header_history_detail.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageView_back"
android:layout_width="60dp"
android:layout_height="#dimen/title_height"
android:background="?attr/colorPrimaryDark"
app:srcCompat="#drawable/vector_expand_left" />
<TextView
android:id="#+id/textview_title"
android:layout_width="match_parent"
android:layout_height="#dimen/title_height"
android:background="?attr/colorPrimaryDark"
android:gravity="center_vertical"
android:text="History Detail"
android:textAllCaps="true"
android:textColor="?attr/colorHeaderText"
android:textSize="16sp" />
</LinearLayout>
Use LinearLayout instead of RelativeLayout. And ser Orientation to vertical. So that the layout place top to bottom.
So, Your parent layout should be link this ->
<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:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/colorBackground">
<!--Your child layouts goes here-->
</LinearLayout>
Copy below code and put in your xml file
<RelativeLayout
android:id="#+id/header_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<include
layout="#layout/view_header_history_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/header_container">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_history_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layoutManager="LinearLayoutManager"
tools:listitem="#layout/fragment_history_detail_item_self" />
</RelativeLayout>
remove above relative layout or you can paste ralative layout content
<RelativeLayout
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="?android:attr/colorBackground">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_history_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layoutManager="LinearLayoutManager"
tools:listitem="#layout/fragment_history_detail_item_self" />
</RelativeLayout>
if you want to fix the layout then u can do one thing as i m thinking....
look the code below....
<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:background="?android:attr/colorBackground"
android:orientation="vertical">
<include
layout="#layout/view_header_history_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout 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="?android:attr/colorBackground"/>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_history_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
app:layoutManager="LinearLayoutManager"
tools:listitem="#layout/fragment_history_detail_item_self" /></LinearLayout>
Try below code. it works for me.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/view_header_history_detail" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerChat"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>

android layout with fragment breaks when toolbar is there

Couldn't find a more appropriate title but my problem is the following. I have a LinearLayout that contains another LinearLayout and a fragment. I also want to add the toolbar but when I do so, then I only see the toolbar and the other screen is just white.
Here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="xeniasis.mymarket.MainActivity">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:weightSum="4">
<LinearLayout
android:id="#+id/categories_layout"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingRight="20dp">
<ExpandableListView
android:id="#+id/categories_listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<fragment
android:id="#+id/mainPane"
android:name="xeniasis.mymarket.Products"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
tools:layout="#layout/activity_main" />
</LinearLayout>
</LinearLayout>
Toolbar:
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:elevation="4dp"
android:padding="5dp"
android:theme="#style/ToolbarTheme" />
And the fragment layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="xeniasis.mymarket.MainActivity">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/swipeRefreshContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="#dimen/activity_vertical_margin">
<GridView
android:id="#+id/productsGridview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:numColumns="3"></GridView>
</android.support.v4.widget.SwipeRefreshLayout>
<android.support.design.widget.FloatingActionButton
android:id="#+id/settings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|start"
android:layout_margin="8dp"
android:clickable="true"
android:elevation="5dp"
android:src="#android:drawable/ic_menu_search" />
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
This only happens when I have a fragment, cause I previously had the same xml with a static layout where the fragment is now.
The problem is that you used a LinearLayout with
android:orientation="horizontal"
and since the toolbar has match_parent as width it occupies all the screen.
Try to use
android:orientation="vertical"
in the root layout

Android Studio: Webview - white space at bottom

In my app there is a white bar at the bottom. I've looked at other questions and they told me to make sure I have everything set to match_parent. I did that and nothing worked.
Picture:
http://i.imgur.com/G3FlTij.png
Any help would be appreciated.
fragment_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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">
<LinearLayout
android:id="#+id/container_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/container_swipe_refresh"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<WebView
android:id="#+id/fragment_main_webview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/global_bg_front" />
</android.support.v4.widget.SwipeRefreshLayout>
<com.google.android.gms.ads.AdView
android:id="#+id/fragment_main_adview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:adUnitId="#string/admob_unit_id"
app:adSize="BANNER" />
</LinearLayout>
<include
layout="#layout/placeholder_progress"
android:id="#+id/container_progress"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<include
layout="#layout/placeholder_offline"
android:id="#+id/container_offline"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
<include
layout="#layout/placeholder_empty"
android:id="#+id/container_empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/toolbar" />
<android.support.v4.widget.DrawerLayout
android:id="#+id/activity_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="#+id/activity_main_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="#+id/activity_main_drawer"
android:layout_width="#dimen/drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:drawSelectorOnTop="true"
android:fastScrollEnabled="false"
android:listSelector="#drawable/selector_clickable_item_bg"
android:background="#color/global_bg_front" />
</android.support.v4.widget.DrawerLayout>
Isn't this bar because of wrongly displayed ads in layout? Did you try to remove it? If bar disappear, it means that there is a problem with displaying ads.
<com.google.android.gms.ads.AdView
android:id="#+id/fragment_main_adview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
app:adUnitId="#string/admob_unit_id"
app:adSize="BANNER" />

How to set the height of a recycler view in android xml

I'm trying to set the height of the recycler view, but I have always the toolbar which is trasparent over the recycler view, and I'm trying to use the android:paddington it doesn't help a lot
here is how it looks now
So how it would be possible to fix that
Here is my code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:id="#+id/linearLayout">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical" />
</RelativeLayout>
and my toolbar xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
local:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
local:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
You are using RelativeLayout as parent layout, change it to vertical LinearLayout and your views will not overlap.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="vertical" />
</LinearLayout>
Make some changes in layout relation like as bellow code:
android:layout_below="#+id/toolbar" on my_recycler_view
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentTop="true"
android:id="#+id/linearLayout">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="fill_parent"
android:layout_below="#+id/toolbar"
android:layout_height="fill_parent"
android:scrollbars="vertical" />
</RelativeLayout>

Categories

Resources