Trying to make my entire layout scrollable - android

I have designed my layout and on smaller phone screens not everything is visible, so I'd like to make it scrollable, could somebody help me with how to go about this? Below is the basic structure of my layout.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/allowanceroot"
android:background="#drawable/background"
>
--TextView--
--EditText--
--TextView--
--EditText--
--TextView--
--EditText--
</LinearLayout>
Do I just contain my TextViews and EditTexts in a LinearLayout, and then contain that in a ScrollView? Also is there anything I need to do programmatically?

Try wrapping it in a scrollview
https://stackoverflow.com/a/4202608/661079
There is nothing else you need to do

Try like this
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView />
<TextView />
</LinearLayout>
</ScrollView>

Related

Vertical and horizantal Scrollview

I'm trying to build Scrollview that scrolls horizontally and vertically
i tried the below code but its not working
<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="#+id/ScrollView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:android="http://schemas.android.com/apk/res/android">
<HorizontalScrollView android:id="#+id/HorizontalScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
/// whatever goes here
</HorizontalScrollView>
</ScrollView>
from this post and tried this post too, is there any open source to this kind of View? Any help would be greatly appreciated.
Try this code snippet.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:scrollbars="vertical">
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="320px" android:layout_height="fill_parent">
<!-- put your subviews here -->
</HorizontalScrollView>

Android Webview with child at bottom

I've been searching both Google and stackoverflow for a while now and haven't found anything answering my question.
I'm wondering about putting a LinearLayout (with no specific known height in pixels) at the bottom of a WebView. This LinearLayout will later be populated with a fragment containing comments for the article displayed in the WebView.
The issue of the problem is that the WebView is almost always larger than the screen so the user has to scroll to read the full article. At the bottom of the scrolling I want the CommentsFragment to be inserted (through the LinearLayout, it takes a few parameters so it can't be loaded directly from the XML).
I've tried a bunch of solutions but all of them make the LinearLayout stick to the bottom of the layout the all time, not on the bottom of the WebView.
My current code is the following, of course not working:
<?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" >
<WebView
android:id="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true" />
<LinearLayout
android:id="#+id/comments_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Thank you for your help!
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<WebView
android:id="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/comments_container"
android:layout_below="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
got it working after a few rounds. The solution was using a ScrollView then inside that a relativelayout mirroring #Karan_rana's answer.
If you want to put the comments fragment below web view then you can try as following and tell me if it works for you
<?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" >
<WebView
android:id="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/comments_container"/>
<LinearLayout
android:id="#+id/comments_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Try this, make sure to have layout_height="wrap_content" in your WebView
<?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:layout_width="match_parent"
android:layout_height="wrap_content" >
<WebView
android:id="#+id/article_webview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:id="#+id/comments_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>

layout_below item inside included layout

I'm trying to figure out a way to align an item in a layout in respect to an item within an included layout.
Here's a visual representation:
And here is example code that I'm looking for (which obviously doesn't work):
Main.xml
<?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" >
<include
android:id="#+id/info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="#layout/info" />
//This would be the dark grey box
<RelativeLayout
android:layout_below="#id/item1">
</RelativeLayout>
</RelativeLayout>
included.xml
<?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="50dp">
<ImageView
android:id="#+id/item1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:paddingLeft="100dp"/>
</RelativeLayout>
I'm assuming the best way to accomplish this would be through dynamically positioning the dark grey box in code, but I have no idea where to start. Any help would be awesome.
Can you make this below your include? Something like this (instead item1 use info):
<?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" >
<include
android:id="#+id/info"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="#layout/info" />
//This would be the dark grey box
<RelativeLayout
android:layout_below="#id/info">
</RelativeLayout>
</RelativeLayout>

Button at Bottom

Im not very good in creating android layouts so I am not able to align the button to the bottom in the MainView.
Picture:
Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical">
<ListView android:id="#+id/lv_pizza" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_weight="1"></ListView>
<Button android:layout_width="fill_parent" android:id="#+id/bt_add"
android:layout_height="wrap_content" android:text="hinzufügen"></Button>
<RelativeLayout android:layout_width="fill_parent" android:id="#+id/relativeLayout2" android:layout_height="fill_parent">
</RelativeLayout>
</LinearLayout>
Please help
This works for a linear layout, note the layout_weight 1 on the list -- that's what pushes the button to the bottom:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView android:id="#+id/lv_pizza"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<Button android:id="#+id/bt_add"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hinzufügen" />
</LinearLayout>
This then looks like this in the UI editor:
Hi you can set like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="#+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical">
<ListView android:id="#+id/lv_pizza" android:layout_width="fill_parent"
android:layout_above="#+id/bt_add" android:layout_height="fill_parent" ></ListView>
<Button android:layout_width="fill_parent" android:id="#+id/bt_add"
android:layout_gravity="bottom" android:layout_height="wrap_content" android:text="hinzufügen"></Button>
</RelativeLayout>
Removing the RelativeLayout will push the button to bottom of the screen...
Use a layout_weight for the components inside the LinearLayout. If the ListView has a weight of 1.0, it should push the button to the bottom. I've done this with a ScrollLayout and it works well, allowing the component inside the scroll layout to actually scroll. You could put your ListView into a ScrollLayout to let it grow beyond the visible size.
Also, the second relativelayout also isn't necessary as it doesn't add anything.
You can set a marginTop in the Button until the bottom or change the layout to relative and set the position.

Android ListView doesn't expand the whole screen

I've problem similar to the one here: Android ListView doesn't expand the whole screen?
The XML is:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="#+id/ResultLayout">
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent">
<ListView android:layout_width="fill_parent" android:id="#+id/ListView"
android:layout_height="fill_parent"></ListView>
</ScrollView>
<LinearLayout android:id="#+id/pagingPanel"
android:gravity="center" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="horizontal"></LinearLayout>
<Spinner android:layout_width="fill_parent" android:id="#+id/ManSpinner"
android:layout_height="fill_parent" />
</LinearLayout>
In this case, I should have a ScrollView or the PagingPanel LinearLayout will disappear.
Edit
The desired layout is to have all the elements stacked on top of each other. but if the elements exceed the page height, a scroll should be added to the ListView.
If you have a vertical LinearLayout, You can't have multiple fill_parent for layout_height of your LinearLayout elements. What layout you would like to achieve? Uniformly divide screen for all elements?
Another problem is that using ListView in ScrollView is not a good idea also because ListView itself is scrollable.
You should write what layout you would like to achieve with your XML. Also generally is a good practice to write your XML in multiple steps and iterate to woking solution layout by layout.
EDIT: Ok, try something like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/ResultLayout">
<ListView android:id="#+id/ListView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout android:id="#+id/pagingPanel"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
<Spinner android:id="#+id/ManSpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>

Categories

Resources