I have a registration form in a LinearLayout as shown below:
When emulator screen is in it's default position it is working fine. But when I rotate the emulator screen it only displays the elements which are fit to screen and remaining are wrap up. As shown in below screen:
Now I want to make this layout scrollable but not getting the idea. Any help will be highly appreciated.
Try putting your LinearLayout inside an ScrollView like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:id="#+id/menu_ll"
android:layout_width="fill_parent" android:layout_height="fill_parent"></LinearLayout>
</ScrollView>
I simply added this code in my activity of AndroidManifest.xml
android:windowSoftInputMode="stateVisible|adjustResize"
Related
Hi guys I am having a real annoying problem that steals my time which could be very simple but ,I need your help .I tried almost all the approaches but none of them worked.
<activity
android:name="activities.UserMainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:label="#string/title_activity_user_main" >
and tried both writing configChanges and not writing even changed my custom class to parcellable but no result.And No Exception is thrown.
And when I debug and watch the the custom adapter it is filled with all items near 30 records .Any help will be APPRECIATED
Ohhhh my god , it is an extremely simple detail . I just edited my activity's layout . I was having my ListView in Relative Layout and this Relative Layout was in a ScrollView , Removing this ScrollView Solved my Day-Consuming Problem.However if I remove android:configChanges="keyboardHidden|orientation|screenSize" part ListView works well but on rotation scrolls back to top (a Tip).
<--<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:id="#+id/listQuestion"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</RelativeLayout>
<!-- </ScrollView> -->
I have 40 Toggle Buttons in my program,and i want to add 40 text views for each button. I need to make my TextView and Toggle button scrollable .How can i do that? Can anybody help me plz??
In your xml add the following
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- Here you put the rest of your current view...Any layout can be placed within the scrollview and this will be scrollable-->
</ScrollView>
I'm using android:windowSoftInputMode="adjustPan" in my manifest.xml.
It's doing me the job just fine but there is something retarded about it.
when i focus an EditText view that's, say in the bottom half of the screen, the title bar is also scrolled with the content of the activity.
image here
all i want is to freeze/float the title bar in place when scrolling the content. just like this:
image here
and no, I don't want to use adjustResize It overlaps views on top of each other
any help is greatly appreciated, been looking for the answer for a long time.
Found it!
Simply changing the root view in the layout xml file to a ScrollView does the job.
I don't even need to specify android:windowSoftInputMode
Of course I have to have everything else in a single layout as the child of the ScrollView
Edit
your .xml file should look like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
... >
<LinearLayout> // could be any other layout but linear works well here
//insert all other views of the activity here
</LinearLayout>
</ScrollView>
The answer suggested by Ace is essentially what is needed. My answer just aims to make things a little clearer.
There are two things you need to do. Firstly in the Manifest set the following on the activity. android:windowSoftInputMode="adjustResize"
Then, in the activity's layout you'll want to set a ScrollView beneath the Toolbar/Title Bar, as shown in the code below.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_height="?attr/actionBarSize"
.../>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
...>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
...>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
From what I understand, here's how it works.
When you open the soft keyboard on your device, it will 'adjustResize' the layout of the activity. As the layout sits in a ScrollView, this is the part which is resized, and made smaller. Therefore the Toolbar/Titlebar will stay in place and the layout in the ScrollView will be scrollable when the keyboard is shown.
I have a xml(registerpage.xml) file and I declared that in a ScrollView so that its scrolling smoothly up and down and I deleted the parent view of this XML.
When I did like this:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/regsrollview"
android:layout_width="fill_parent"
android:fillViewport="true"
android:layout_height="fill_parent">
<include android:id="#+id/registrationlayout"
layout="#layout/registerpage"/>
</ScrollView>
the above code I have written in main.xml and deleted the parentview of registerpage.xml. now the problem is registerpage.xml is not scrolling as before and the softkeypad is disturbing. Now I want to give the controls to the registerpage.xml in activity so that it will scroll up and down(wit some velocity)
How to do this?
Thanks in advance...!
My current layout displays activity that is not full screen (that's OK).
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="100dip"
android:layout_height="200dip" >
<TextView android:layout_height="wrap_content" android:id="#+id/textView1"
android:layout_width="fill_parent" android:text="#string/hello"></TextView>
I also added android:theme="#android:style/Theme.Translucent" to manifest for my activity.
My 200x100dip activity now shows in the upper left corner. How can i specify position of my linear layout (or my activity)?
You can use either FrameLayout or RelativeLayout as outer most layout for this. Ant then use absolute position in dp or android:layout_centerInParent or similar.
I believe your Activity´s outmost layout element (LinearLayout) will be placed in a FrameLayout that is the parent given from Android. I suggest you let your outmost layout match_parent/fill_parent in layout_height and _width and then center the content inside it with gravity="center" on your outmost layout. By letting the outmost layout being transparent and not catch click element it will appear as layout in the middle where elements behind is visible. If Im correct guessing that's what you want to achieve here.
put that layout in another absolute layout in which you use android:layout_width="fill_parent" and android:layout_height="fill_parent" the other thing you can do is to use this: http://www.droiddraw.org/
you can move your elements around manually with that and it will give you the XML code that is used to do that. I found it very useful in laying out XML in android.