How to scroll layout with adjustPan - android

I have a nestedscrollview in my fragment which is having button below of nestedscrollview, when keyboard arrives button moves above of the keyboard and the entire layout handle its scrolling properly but the issue is with the background image which get shrink.
I've used android:windowSoftInputMode="stateAlwaysHidden|adjustResize" in my Manifest file and if i use adjustPan then view does not scroll entire layout shift up.
I know this question is asked so many times but I didn't found proper answer.
Please Help.

Follow steps like below :
After that you are able to achieve what you want:(Below code is MainActivity.xml code)In this code Image View is your background image.
<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="#color/colorAppBack"
tools:context=".activities.LoginActivity">
<ScrollView
android:id="#+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/login_image_min_2" />
</ScrollView>
// Your container layout which contains fragments like framelayout or what ever you are using
</RelativeLayout>
In manifest:
android:windowSoftInputMode="adjustResize"

Your image is shrinking because you have added image inside scroll view too.
Try to add image out side the scroll view as image is background image.
This way Image wont scroll.

Related

RecyclerView (wrap_content) inside of a BottomSheetDialogFragment

I'm facing a tricky situation here and I don't know how to solve this problem.
In my project I have a custom BottomSheetDialogFragment and in the layout a FrameLayout to add or replace Fragments.
Now I have a Fragment and inside I have a RecyclerView with the height:="wrap_content" because I want the BottomSheetDialogFragment only use the necessary space. Everything looks great, the problem appear when I put another view inside of the same layout and set the RecyclerView bellow or above of that view.
The RecyclerView ignores the size of the other view (or views) and always grows to the max screen size, and then it's no possible to see a few elements and even scroll.
I saw a solution, some developers are suggesting to add paddingBottom equals to the height of the view. But in my case doesn't works because I want to have a dynamic solution.
Above I'll share a few images of the problem and GitHub Repository with a sample.
Thanks for your attention!
I've manage to do what you need just need to use this as your fragment_sample.xml:
<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:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="#+id/rclItems"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"/>
<Button
android:id="#+id/btnAddMoreItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/rclItems"
android:text="#string/add_1_item"/>
</LinearLayout>
Explanation
Using a LinearLayout gives you the ability to work with weight, and the vertical orientation allows you to place an item below the other. The weight on the recyclerview will increase the height of it as needed until filling the screen. The next item you add would be added to the recyclerview but you'll need to scroll the list to see it
The android developers blog says that :-
The scrolling containers in your bottom sheet must support nested scrolling .
Try changing your fragment_sample.xml as below to make the recyclerview scroll working and to make the add button persistent.
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:id="#+id/next"
android:layout_above="#id/btnAddMoreItems"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/rclItems"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</android.support.v4.widget.NestedScrollView>
<Button
android:id="#+id/btnAddMoreItems"
android:layout_width="match_parent"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:text="#string/add_1_item"/>
</RelativeLayout>
Note: making bottomsheet layout a child view of CoordinatorLayout will allow you to get the implement BottomSheetBehavior and recieve its transitions callbacks .

Fixed Button in scrollview

I want to make a view( a button actually) which is inside a scrollview , but when the user scolls down and the button is going up, it moves up only till it reaches the top of the visible screen and then stays there like a fixed header until the user scrolls up again and then it returns to its original position.
I have given the screens for understanding ;
At Start
Then
Change you parent viewgroup to RelativeLayout and then make a Button and ScrollBar as a direct child of this RelatieveLayout.
You can simply achive this by
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
------put your code here-----/>
<Button
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>

Android:Bottom view should not appear above keyboard When soft keyboard open But Scroll should work. How to achieve?

I am using a Relative layout as root view and i have a view in bottom. When i am opening keyboard my View goes up and then i use
<activity
android:windowSoftInputMode="adjustPan">
</activity>
View that need to be in bottom
After doing this my View is not showing up but Still my content is not scrolling up, it's behind the screen. I want to scroll my content till the bottom
How to achieve it? Please help me.
Scroll the view after keyboard open
try this
android:windowSoftInputMode="adjustResize"
And if you are using full screen activity then nothing will work.
Try including your layout inside a ScrollView, it will allow you to scroll when keyboard is open.
Do like this...(Tested)
<?xml version="1.0" encoding="utf-8"?>
<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">
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center">
//define you bottom view here
</RelativeLayout>
<ScrollView
android:id="#+id/scrollableContents"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="false"
android:layout_above="#id/footer">
//Rest of the view except bottom view
</ScrollView>
</RelativeLayout>
And in manifest define
android:windowSoftInputMode="stateVisible|adjustPan"
This code is working great for me.

Gallery inside a ScrollView - vertical scrolling doesn't work

There were some questions about ScrollViews inside Gallery etc., however I have something exactly opposite here and I can't find any solution.
The problem: I have multiple Galleries in one ScrollView. Horizontal scrolling for Galleries works fine (nothing changed here, just a standard Gallery class from SDK), but vertical scrolling for ScrollView, for whole activity does not. It looks like Galleries are intercepting touch events. Could you please help me to solve this out?
This is my layout xml:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollview_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:id="#+id/layout_home"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
...>
<Button
.../>
<Gallery
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gallery_..."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
... />
<TextView
... />
</RelativeLayout>//this layout is repeated few times, because I have multiple galleries
</RelativeLayout>
</ScrollView>
Thanks!
You could make the top RelativeLayout (which contains all the other RelativeLayouts), to be about 30-40 dp smaller in width then the ScrollView. This allows the user to touch an area of the ScrollView which is not covered by a Gallery, so the Touch is not intercepted and should work as expected.

Displaying an image larger than the device's screen

I'd like to display an image larger, in size, than a device's screen without resizing the image. It has to be centered on the screen. How can I do this?
use scrollview with image view and set height of that scroll view
Example
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="#+id/accountIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</ScrollView>
I noticed that I need to use normal (vertical) and horizontal ScrollView in order to scroll both directions. Let me know please if there is another way.
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/scrollView" >
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/horizontalScrollView">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/imageView3"
android:src="#drawable/big_map"/>
</HorizontalScrollView>
</ScrollView>
It started display form left upper corner of the image. If I tried to use android:layout_gravity="center" then I got white part on right or bottom. So centering is not working for me.
Option 2: use WebView control, and load it with image onCreate.
Derive from View, overwrite onDraw and draw it on the screen.
You can also work with framelayout. The layout can be bigger than the screen

Categories

Resources