Android ScrollView not scrolling - android

I have solved my question. I chose to instead have a header and a footer that are always located at the bottom and top of the screen respectively. Then I created a "center content" which I enclosed within a ScrollView layout. I have updated the code below if people are interested in seeing what it now looks like.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:background="#FFFFFF">
<LinearLayout android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#layout/header"
android:layout_alignParentTop="true">
<ImageView android:src="#drawable/logo"
android:contentDescription="#string/logo_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dip"/>
</LinearLayout>
<ScrollView android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="350dip"
android:layout_below="#id/header">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="20dip" >
<!-- Email Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#372C24"
android:text="#string/email"/>
<EditText android:id="#+id/email_field"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:singleLine="true"
android:inputType="textEmailAddress"/>
<!-- Password Label -->
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:textColor="#372C24"
android:text="#string/password"/>
<EditText android:id="#+id/password_field"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:inputType="textPassword"/>
<!-- Login button -->
<Button android:id="#+id/login_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dip"
android:text="#string/login"/>
<!-- Register button -->
<Button android:id="#+id/register_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dip"
android:text="#string/register_button"/>
</LinearLayout>
</ScrollView>
<LinearLayout android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="90dip"
android:background="#layout/footer"
android:layout_alignParentBottom="true">
</LinearLayout>
</RelativeLayout>

For me, remove android:windowSoftInputMode="adjustPan" of the <activity> tag in AndroidManifest.xml file solved the problem.

I removed this line from the AndroidManifest.xml file
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
and added this line
android:theme="#android:style/Theme.NoTitleBar"
it has both fixed my scrolling app and made my app look more visually appealing. However, I am not sure if this is the correct fix.

for me the problem was that the LinearLayout in the ScrowView had android:layout_height="wrap_content".
<ScrollView android:id="#+id/scroll_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout android:id="#+id/layout_inside"
android:layout_width="match_parent"
android:layout_height="wrap_content" --> This should not we wrap_content, but specific height.
android:orientation="vertical" >

The ScrollView is not working when used as the root element of an XML layout.
It has to be wrapped inside a LinearLayout.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView android:id="#+id/scroll_view1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true" >
<LinearLayout android:id="#+id/layout_inside"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
Have a fun ! !

ScrollView must have Linearlayout control as a immediate child, you have relative layout, I think that might be causing the problem.
Check this link out, also this. Look at their layout xmls..

Related

Layout not showing after working previously

I'm trying to implement a landscape layout for my Android project. I had it semi working previously, other than that "leftRightLinear" was being overlapped slightly by the button layout at the bottom.
Since trying to fix that problem, I've given up and rolled back to my working version, which is no longer working and I can't figure out why.
The contents of pendingLinear and semesterLinear aren't displaying.
Any ideas?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mainLinear"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/leftRightLinear"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true" >
<LinearLayout
android:id="#+id/leftLinear"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="fill_parent" >
<TextView
android:text="#string/pendingUnits"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ScrollView
android:id="#+id/pendingScroll"
android:layout_width="fill_parent"
android:layout_marginBottom="0dp"
android:layout_height="0dp"
android:background="#drawable/border">
<LinearLayout
android:id="#+id/pendingLinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:id="#+id/rightLinear"
android:orientation="vertical"
android:layout_width="0dp"
android:layout_weight="0.5"
android:layout_height="fill_parent" >
<TextView
android:text="#string/semesters"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<ScrollView
android:id="#+id/semesterScroll"
android:layout_width="fill_parent"
android:layout_marginBottom="0dp"
android:layout_height="0dp"
android:background="#drawable/border">
<LinearLayout
android:id="#+id/semesterLinear"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/border_confirm"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/saveButtonSemester"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:onClick="clickSave"
android:text="#string/button_save"
/>
<Button
android:id="#+id/confirmBtn"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="#string/confirm"
android:onClick="clickConfirm"
/>
</LinearLayout>
The contents of pendingLinear and semesterLinear aren't displaying
It's because both of your ScrollView are set android:layout_height="0dp". Change them to android:layout_height="fill_content", like so:
<ScrollView
android:id="#+id/pendingScroll"
android:layout_width="fill_parent"
android:layout_marginBottom="0dp"
android:layout_height="fill_parent">
About this problem
"leftRightLinear" was being overlapped slightly by the button layout at the bottom
To let leftRightLinear sit above the button layout, first give the button layout a name
<LinearLayout
android:id="#+id/buttonLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true" >
Then add this attribute to leftRightLinear, android:layout_above="#+id/buttonLayout", like so:
<LinearLayout
android:id="#+id/leftRightLinear"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/buttonLayout"
android:layout_alignParentTop="true" >
Here's the result: (Background of the left scrollview is set black)
pendingLinear and semesterLinear do not have any contents so there is nothing to be shown, they are there - they exist - they are just empty.
Are you adding contents to them dynamically ? if so I'd like to look at the code otherwise try inserting a TextView inside one of them (or both) to confirm that they are being shown.

Android full screen, EditText pushes other view up

I am working on an app and have a problem.
I have an vieww like the image below with an image and an edittext field the right position. But when i click on the edittext field and it gets the focus it pushes the other view up.
I have the full screen flag and if i dont use that it works perfect and the image keeps theire position and dont pushed up. I need that with full screen flag.
Is there someone who have some example or can help me. I have used the 'windowSoftInputMode' with all the posibles values.
Here my layout code and examples how it now works and how it needs to be.
xml layout source:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:fillViewport="true"
android:orientation="vertical"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical|none" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<!-- layout for images -->
<RelativeLayout
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="top" >
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/image"
android:contentDescription="TODO"/>
</RelativeLayout>
<!-- layout for edit text -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:layout_alignTop="#id/imageview"
>
<EditText
android:id="#+id/tekstbox"
android:imeOptions="flagNoExtractUi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Here is the image how i start in the activity
When i click in the edittext field i want my view to react as below:
But when the edittext gots focus it pushes everything up like below:
Does someone know how to solve this with the fullscreen flag on?
Thanks.
User this line of code in your Manifest.xml. In the activity where the problem is occuring
<activity
android:windowSoftInputMode="stateVisible|adjustNothing">
</activity>
Add the below line in your manifest file in activity tag:
android:windowSoftInputMode="adjustResize"
and add ScrollView in your layout file like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:fillViewport="true"
android:orientation="vertical"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical|none" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<!-- layout for images -->
<RelativeLayout
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="top" >
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/image"
android:contentDescription="TODO"/>
</RelativeLayout>
<!-- layout for edit text -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:layout_alignTop="#id/imageview"
>
<EditText
android:id="#+id/tekstbox"
android:imeOptions="flagNoExtractUi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Add the below line in your manifest file in activity tag:
android:windowSoftInputMode="adjustPan|stateHidden"

Why is NoActionbar Theme affecting ScrollView & overall Layout?

So i have a layout in Android where its a vertical LinearLayout that encompasses A ScrollView, LinearLayout, LinearLayout.
I made each child take about roughly a 3rd of the screen. When I have them Holo or Holo.Light with an ActionBar is looks as expected:
However, when I change the Theme to Holo.NoActionBar or Holo.Light.NoActionBar, for some reason, it completely ignores my android:layout_weight, or even my ScrollView. Like all my contents in my scroll view are no longer collapsed.
It then looks like this:
Why does this happen? I cannont figure out why. I even made a custom theme in my styles.xml and the problem still existed. How come ScrollView only works when I have an ActionBar?
Here is my code:
<?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"
android:paddingTop="10dp"
android:weightSum="100"
>
<ScrollView
android:layout_height="0dp"
android:layout_width="fill_parent"
android:layout_weight="30">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/tvEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/email" />
<EditText
android:id="#+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textNoSuggestions" />
.......................
</LinearLayout>
</ScrollView>
<LinearLayout
android:layout_height="0dp"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_weight="40">
<Button
android:id="#+id/bSendEmail"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/sendEmail" />
</LinearLayout>
<LinearLayout
android:layout_height="0dp"
android:layout_width="fill_parent"
android:orientation="vertical"
android:layout_weight="30">
<AnalogClock
android:id="#+id/analogClock1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</LinearLayout>

how to make an android view scrollable when the keyboard appears?

I have a view with some fields (name, email, password, register button) :
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ViewFlipper
android:id="#+id/viewflipper"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
//Layouts
</ViewFlipper>
</ScrollView>
When I focus an edittext field, the keyboard appears and is overlaying the lower fields on the view. So I can't see them when the keyboard is present. I would like to know how to make the view scrollable so that I can see the lower fields. And additionally, how to make the view scroll automatically to make the focused field visible.
You need to include android:windowSoftInputMode="adjustResize" attribute for your activity in the AndroidManifest.xml file - and then Android should do the resizing for you automatically:
<activity android:name="..."
...
android:windowSoftInputMode="adjustResize">
...
/>
I have created simple xml file.
step 1. you can scroll when key-pad is appeared.
step 2. when you click on Text-Field it will come on Focus/above keypad.
<ScrollView android:id="#+id/ScrollView01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:weightSum="1.0"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:id="#+id/l_layout">
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/editText1"
android:layout_marginTop="100dp">
<requestFocus></requestFocus>
</EditText>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/editText2"
android:layout_marginTop="100dp">
</EditText>
</LinearLayout>
</ScrollView>
In my case #Aleks G solution was not working. so I resolved my problem with
<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"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/registration_scroll_view"
android:layout_alignParentTop="true"
android:layout_above="#+id/btn_register_submit"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<!--This comment will be replaced
by your focusable views-->
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/btn_register_submit"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#drawable/form_action_button_green"
android:gravity="center"
android:text="#string/submit"
/>
</RelativeLayout>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ViewFlipper
android:id="#+id/viewflipper"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scroll_container">
//Layouts
</ScrollView>
</ViewFlipper>

How to make a edittext view fill the parent element in android

I have two edittext views. One of them has only one line, its the title. But the other one should fill the linearlayout to the end, but it doesn't.
I updated the code so this is my whole xml for this app. I hope someone can find what's wrong. The part that i want to form like this is the part inside the LinearLayout named addView.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#ffffff">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<Button
android:id="#+id/addButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/addbuttonstyle"
android:layout_weight="20"/>
<ImageView
android:id="#+id/titleView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/titleview"
android:layout_weight="60"/>
<Button
android:id="#+id/orderButton"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/orderbuttonstyle"
android:layout_weight="20"/>
</LinearLayout>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/addView"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<EditText
android:id="#+id/textBoxTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="note title"
android:singleLine="true"
/>
<EditText
android:id="#+id/textBoxContent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:hint="content"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/backgroundLayout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/background"
/>
</FrameLayout>
I changed textBoxTitle's height to wrap_content and I see this:
Is this what you were hoping for? Also if you want content to appear in the upper-left corner use this attribute:
<EditText
...
android:gravity="top"
/>
So i found what was wrong.
I needed to set layout_height (of the textBoxContent view) to 0dp and layout_weight (of the textBoxContent view) to 1.
The first view should have android:layout_width="wrap_content"

Categories

Resources