Forcing adjustPan in activity containing ScrollView - android

My layout looks like this:
<RelativeLayout>
<RelativeLayout>
</RelativeLayout>
<ViewFlipper>
<ScrollView>
<LinearLayout>
<EditText />
</LinearLayout>
</ScrollView>
</ViewFlipper>
<RelativeLayout>
</RelativeLayout>
</RelativeLayout>
When focused on the EditText in the middle, the soft keyboard pops up as expected, However it always resizes the layout even though I have android:windowSoftInputMode="adjustPan" in the manifest.
The problem with resizing is that only the ScrollView shrinks, leaving the RelativeLayouts above and below it intact, which can almost completely obscure the EditText.
I've tried hiding the RelativeLayouts when the keyboard is shown (that's another sad story), but adjustPan sounds more suitable. However it has no effect on this activity.
How can I force adjustPan to work despite the presence of the ScrollView?
Update:
SO won't let me answer my own question, but the solution is setting android:isScrollContainer="false" on the ScrollView.

Good question mostly Developers do the same thing but this is not a correct way you have need to do. This will help you.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ViewFlipper>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText />
</LinearLayout>
</ScrollView>
</ViewFlipper>
<LinearLayout>
You should take LinearLayout with orientation as Vertical or horizontal view where you have never adjustment problem created.this is very simple.

try this in your manifest's the activity tag:
android:windowSoftInputMode="stateVisible|adjustPan"

Related

EditText going beyond the window bound when keyboard comes in Android

In my manifest.xml I have set this to my current Activity.
<activity
android:name=".StockAdjustment"
android:theme="#style/CustomActionBarTheme"
android:label="#string/Metrix"
android:windowSoftInputMode="adjustResize" >
</activity>
my problem is when the keyboard appears my EditText going up too much. It beyond the view's upper bound and cant even see what I am typing.
No matter whatever I put for android:windowSoftInputMode="adjustResize" the same result comes.
Please help me.
Thanks
UPDATE
UPDATE 2
<ScrollView
style="#style/ScrollViewBase.Normal.Vertical"
android:layout_weight="1"
tools:isScrollContainer="false">
Set android:windowSoftInputMode="stateVisible|adjustPan|adjustResize"
Also, if you have a ScrollView in your layout, add android:isScrollContainer="false" to your ScrollView
Try this and also set the android:fitsSystemWindows="true" to parent layout element.
<ScrollView
style="#style/ScrollViewBase.Normal.Vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:isScrollContainer="false">
Finally I achived this my changing the structure of my layout.xml.
I changed my layout xml file into this
<LinearLayout style="#style/LinearBase.Normal.Vertical" >
<ScrollView
style="#style/ScrollViewBase.Normal.Vertical"
android:layout_weight="1"
android:fitsSystemWindows="true"
tools:isScrollContainer="false">
<LinearLayout style="#style/LinearBase.Normal.Vertical">
<LinearLayout
android:id="#+id/table_layout"
style="#style/LinearBase.Normal.Vertical"
android:focusable="true"
android:focusableInTouchMode="true">
<TextView
style="#style/TextViewBase.Title"
android:tag="SCREEN_LABEL"></TextView>
<TextView
style="#style/TextViewBase.Emphasis"
android:tag="SCREEN_TIP"></TextView>
</LinearLayout>
<ListView
android:id="#+id/serialList"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</ScrollView>
<include layout="#layout/stock_adjustment_menu_bar" />
</LinearLayout>
Previously, my Scrollview is shrinking/paning, then the ListViewgoing up and I cant see the content inside the ScrollView. After I changed the layout structure, my whole content(Textviews,EditTexts adding by the code and ListView) is inside a single ScrollView. So shrinking/paning happens by considering the whole content of inside the Scrollview.
Make sure to disable the scrolling for parent view when touch the ListView

ScrollView does not work with ActionBar

ScrollView does not work, I have a layout with some components like EditText, and when I'm typing something EditText keyboard rises, and along the component, however it appears above the other, the ScrollView does not respond to their function.
Already googled, and found some similar problems, but none solved my problem.
Below my layout.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:padding="5dp" >
<TextView
android:id="#+id/txtDescricaoDocumento"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/edtDescricaoDocumento"
android:layout_alignBottom="#+id/edtDescricaoDocumento"
android:gravity="right"
android:text="Descrição:"
android:textAppearance="?android:attr/textAppearanceMedium" />
...
And my manifest.xml
<activity
android:name=".LancarDocumentoAcaoActivity"
android:windowSoftInputMode="adjustResize" >
</activity>
Couple things I've tried this without the relative layout inside of the scroll view...and scroll view worked perfectly.
1.Is relative layout necessary inside a linear layout? Try removing it if not.
2.Is the attribute WindowSoftInputMode necessary for the corresponding class if not you will have the soft keyboard covering view elements like it is mentioned.
Let me know if this works.

WindowSoftInputMode and ScrollView

My Android app's main activity looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background"
android:orientation="vertical" >
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:orientation="vertical"
android:paddingLeft="60dp"
android:paddingTop="53dp" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/billAmountText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/billAmount_string"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/billAmount"
android:layout_width="173dp"
android:layout_height="wrap_content"
android:layout_below="#id/billAmountText"
android:layout_marginTop="3dp"
android:inputType="numberDecimal" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
In order to make sure the background image (defined in the first RelativeLayout) does not get squeezed when the keyboard pops up, I have set android:windowSoftInputMode="stateVisible|adjustPan in the manifest file for my activity. All good with the background and layout now, nothing gets resized.
But the problem is that my ScrollView doesn't work now because I suppose the system thinks the window doesn't need resizing due to my above modification to the manifest - so the ScrollView is not activated. The opposite happens when I take android:windowSoftInputMode="stateVisible|adjustPan out, the scrolling works, but the background gets squeezed when the keyboard pops out.
Is there any way to code it so that my background doesn't get squeezed, and my ScrollView still works? Thanks!
Try to use in your activity the property windowSoftInputMode with the following values:
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"
I don't know if it's necessary but you can try to add to your layout's ScrollView tag the fillViewPort to true.
So it should look like something I show you below:
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<!-- Other Views -->
</ScrollView>
Let me know about your progress.
In your scrollview put a relative layout, child 0 is an imageview, and child 1 is your content. Use the imageview for your background image (src) rather than the background of the scrollview. The imageview will respect scaleTypes, whereas the background of a layout will not.

Android layout are fixed?

I am putting more than 15 buttons in one .xml file. But it seem only to be displaying the top 9 of them ? Why aren't the other buttons showed or can't I scroll down to see them?
I am using a LinearLayout with tags.
Are you using a LinearLayout perhaps to contain the buttons? Or any other layout that's not contained in a ScrollView? Good chance your buttons are being drawn, they are just outside your screen.
Wrap your layout in a ScrollView like so:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:scrollbars="none" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- your buttons here -->
</LinearLayout>
</ScrollView>
This makes your layout scrollable, so you will be able to just scroll down and see your buttons.
Did you use this?
android:orientation="vertical"
Please post your code,
Are you wrapping everything is ScrollView?:
<ScrollView android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</ScrollView>
More info http://developer.android.com/reference/android/widget/ScrollView.html

Activity does not scroll when rotating screen

when I turn the phone and the screen is rotating I cannot see the whole screen anymore. This is ok but I cannot scroll! Do I have to set some flag or property for scrolling? This is part of my xml...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_width="fill_parent" android:layout_height="fill_parent" >
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:stretchColumns="*">
...
</TableLayout>
<TableLayout android:layout_width="fill_parent" android:layout_height="wrap_content"
...
</TableLayout>
</LinearLayout>
Thanks!
You have to put your complete layout inside a ScrollView in order for it to scroll.
It scrolls if your layout height is more than the screen height, which happens generally in landscape mode.
In your case put the LinearLayout inside a ScrollView, since ScrollView can only have 1 child.
You must know that in order to use an scrollView , you must put only one component inside (maybe a linearLayout) .Maybe that's your problem if you are trying to put in more components at that level.

Categories

Resources