Android - Scrollview don't push up when keyboard appear - android

My app have an activity with layuot like this
<RelativeLayout
android:id="#+id/layoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backgroundchatfixed">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/layoutKhungChat"
android:id="#+id/svChat">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/layoutChat">
</LinearLayout>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_khungchat"
android:layout_alignParentBottom="true"
android:id="#+id/layoutKhungChat">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/khungchat_chat"
android:layout_centerVertical="true"
android:id="#+id/etChatbox"/>
</RelativeLayout>
</RelativeLayout>
When i touch my Edittext, only layout "layoutKungChat" push up.
Any solution to push up also Scrollview above it?
Thanks.

Try adding this to the activity tag in the manifest:
android:windowSoftInputMode="adjustPan"

use this code
<RelativeLayout
android:id="#+id/layoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backgroundchatfixed">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/background_khungchat"
android:layout_alignParentBottom="true"
android:id="#+id/layoutKhungChat">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/khungchat_chat"
android:layout_centerVertical="true"
android:id="#+id/etChatbox"/>
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/layoutKhungChat"
android:id="#+id/svChat">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/layoutChat">
</LinearLayout>
</ScrollView>
the one in the last always be written over the other layouts so if you want like buttons to be above an image layout as an example write it inside of layout below the image

Related

Linear Layout overlapping with Scroll view and other Linear Layout

Recently i have encounterd a problem. My linear layout where my edit text and image button is in is overlapping with my toolbar and my scroll view. I've tried other things like layout_below etc and nothing worked. Groupchat.xml
<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"
tools:context=".GroupChatActivity"
android:orientation="vertical">
<include
android:id="#+id/group_chat_bar_layout"
layout="#layout/app_bar_layout">
</include>
<ScrollView
android:id="#+id/my_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/group_chat_bar_layout"
android:layout_above="#+id/myLinearLayout">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/group_chat_text_display"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textAllCaps="false"
android:textSize="20sp"
android:textColor="#android:color/background_dark"
android:layout_marginStart="2dp"
android:layout_marginEnd="2dp"
android:layout_marginBottom="50dp"/>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/myLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:id="#+id/input_group_message"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:hint="Write message..." />
<ImageButton
android:id="#+id/send_message_button"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:src="#drawable/send_message" />
</LinearLayout>
This is how the preview of the groupchat.xml file looks in Android Studio:
enter image description here
This was how the app looked with this code.
This are the results
Just in case, this is the code of my toolbar: Appbarlayout.xml
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="#color/colorPrimary"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light">
It in a seperate xml because i'm using it for other activities in my app to thats why theres ang include in th Groupchat.xml
ALSO I AM FOLLOWING THIS TUTORILA. I suggest you go ther and see it because that is what i followed.
go to this video
Thank you.
The problem is with layout placements. your LinearLayout with ID: myLinearLayout is not aligned anywhere in RelativeLayout that's why it is getting rendered on top of the screen. make following changes and your good to go.
in your LinearLayout with id: myLinearLayout, add this line:
android:layout_alignParentBottom="true"
like this:
<LinearLayout
android:id="#+id/myLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
Add
android:layout_below="#+id/group_chat_bar_layout"
this line to LinearLayout
<LinearLayout
android:id="#+id/myLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/group_chat_bar_layout"
android:orientation="horizontal">
<EditText
android:id="#+id/input_group_message"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:hint="Write message..." />
<ImageButton
android:id="#+id/send_message_button"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:src="#drawable/bkg" />
</LinearLayout>`

RecycleView Not Scrolling by adding RelatvieLayout below It

I have viewpager at the top to slide and view images . and after a list to see remaining images or whatever i want to display in list and after that i have a RelativeLayout below this list which i will populate with the Code
Now Issue is :-
I am facing a problem with RecycleView . It was working fine until i add a RelativeLayout to parentofbottom and setting RecycleView property to above this RelativeLayout . Now Issue is RecycleView is not scrolling at all . whats wrong with the code. What needs to be change .Or Suggest me anyother way to achieve this design
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<RelativeLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:focusableInTouchMode="true"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/relativeHeader"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#color/headecolor" >
<Button
android:id="#+id/btnOpenDrawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#drawable/menu_icon" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#drawable/alert_icon" />
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textStyle="bold"
android:text="A La Une"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/blackColor" />
</RelativeLayout>
<android.support.v4.widget.NestedScrollView
android:id="#+id/scroler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/relativeHeader"
android:fillViewport="true"
android:background="#android:color/white" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:background="#android:color/white" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:descendantFocusability="blocksDescendants"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/rlPager"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<egdigital.alpes1.view.WrapContentViewPager
android:id="#+id/view_pager"
android:layout_width="match_parent"
android:layout_height="220dp"
android:adjustViewBounds="true"
android:background="#drawable/news_img_transparent"
/>
<ImageView
android:id="#+id/imageView_dot"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/view_pager"
android:layout_alignParentLeft="true"
android:src="#drawable/scroll_dot1" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlRecycle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/relativeLayout1"
android:layout_above="#+id/rlMiniPlayer"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="80dp">
</android.support.v7.widget.RecyclerView>
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlMiniPlayer"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
>
</RelativeLayout>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
</RelativeLayout>
<fragment
android:id="#+id/navigation_drawer"
android:name=".NavigationDrawerFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
android:layout_marginLeft="25dp"
tools:layout="#layout/fragment_navigation_drawer" />
</android.support.v4.widget.DrawerLayout>
1) Change
android:layout_below="#+id/relativeLayout1"
to android:layout_below="#id/relativeLayout1" and change anywhere else you have layout_below or layout_above
+ is used when creating a new id. When giving an already created id we use it without +
2) You don't really need RelativeLayout with id rlRecycle. You can directly move layout_below and layout_above attributes to RecyclerView because it's already under top level RelativeLayout
I Found The Solution . i know there are lots of extra RelativeLayouts . Know I removed it . and putted rlMiniPlayer below the nested scrollview
Because I am using nestedscrolling=true . in the code . This is creating the problem
Like This :-
</android.support.v4.widget.NestedScrollView>
<RelativeLayout
android:id="#+id/rlMiniPlayer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
</RelativeLayout>

Android: how to avoid soft keyboard pushing up my layout?

This is my layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="#layout/include_toolbar_actionbar"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/background"
android:paddingTop="#dimen/keyline_5"
android:paddingRight="#dimen/keyline_2"
android:paddingLeft="#dimen/keyline_2"
android:orientation="vertical">
<TextView
android:id="#+id/title"
style="#style/FlatCardTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TITLE" />
<EditText
android:id="#+id/content"
android:inputType="textMultiLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/keyline_1"
android:layout_marginBottom="#dimen/keyline_4"
android:lines="16"
android:minLines="4"
android:maxLines="16"
android:scrollbars="vertical"/>
</LinearLayout>
</LinearLayout>
<include layout="#layout/include_visibility_right_editor" />
</RelativeLayout>
The layout "include_visibility_right_editor" must be always at the bottom. Unfortunately, when the soft keyboard appears, all the layout is pushing up...
Thank for your help guys!
Use the following property in manifest activity declaration:
android:windowSoftInputMode="adjustNothing"
Also check other options according to your requirement

Two buttons showing when only creating one in XML

I am creating my layout entirely in XML. I wish to show a ListView and always have a button at the bottom of the screen like in the default FullScreenActivity. However, the issue is that the button that is at the bottom is also appearing at the top of the screen.
<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"
android:background="#ff000000"
tools:context=".ChannelNameActivity">
<ListView
android:id="#+id/channelListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
android:layout_weight="1"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/black_overlay"
android:orientation="horizontal"
tools:ignore="UselessParent">
<Button
android:id="#+id/dummy_button"
style="?metaButtonBarButtonStyle"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/dummy_button" />
</LinearLayout>
</RelativeLayout>
(Code note from OP's previous question: ArrayAdapter unable to update contents)
Because in your onCreate() you are adding Activity Layout as Header View to your ListView which is unnecessary (not required).
So Just remove below code lines from onCreate()
final View contentView = (View)getLayoutInflater().inflate(R.layout.activity_channelname, null);
channelListView.addHeaderView(contentView);
Here you have to use android:layout_above="#+id/lnlLayout" attribute in ListView and android:alignParentBottom="true" on LinearLayout
<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"
android:background="#ff000000"
tools:context=".ChannelNameActivity">
<ListView
android:id="#+id/channelListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/lnlLayout"
android:keepScreenOn="true"/>
<LinearLayout
android:id="#+id/lnlLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/black_overlay"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
tools:ignore="UselessParent">
<Button
android:id="#+id/dummy_button"
style="?metaButtonBarButtonStyle"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/dummy_button" />
</LinearLayout>
</RelativeLayout>

How to fill the screen with only one element?

I want to make an activity with 2 elements in the screen, one in the bottom, with a fixed size, and one on top of this which one must fill the screen.
How I can do that in a Layout?
Thank you
use layout_weight="1" for 1st element and put layout_height="0dp" and use linearlayout as the parent which contains the 2 elements.
Use below code:
<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" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:text="#string/hello_world" />
<TextView
android:id="#+id/textView2"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:text="test" />
</LinearLayout>
Or you can do this,
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_above="#+id/ll1"
>
</LinearLayout>
<LinearLayout
android:id="#+id/ll1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
>
</LinearLayout>
Add this to the first element:
android:layout_weight="0.8"
and for the second one
android:layout_weight="0.2"
You can use Relative Layout like...following example
<//you are second element
android:id="#+id/ui_radiogroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:clickable="false"
android:orientation="horizontal" >
<///you are second element>
<//you are First element
android:id="#+id/ui_pager"
android:layout_width="wrap_content"
android:layout_above="#id/ui_radiogroup"
android:layout_height="wrap_content"
android:scrollbars="horizontal" />
Other OPtion use Linear Layout assign android:layout_weight to each element depending upon your requirement
try this,
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TextView
android:id="#+id/footertext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:text="Footer" />
<TextView
android:id="#+id/centertext"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/footertext"
android:gravity="center"
android:text="center" />
Here is the complete trick :
Use a RelativeLayout to wrap your two items,
Put layout_alignParentBottom="true" on your bottom item
And layout_above="#+id/your_bottom_item_id" on your top item
Here is a complete working example that you can cpy/paste :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/top_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_above="#+id/bottom_layout">
</LinearLayout>
<LinearLayout
android:id="#+id/bottom_item"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="vertical"
android:layout_alignParentBottom="true">
</LinearLayout>
</RelativeLayout>
Simply use layout_weight="1" for first element and layout height should be match_parent.

Categories

Resources