Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I place new items under scrollview

I have a vertical scrollable layout with lots of items, working fine.
I am trying to place a new linearlayout to the bottom of the screen that would NOT be part of the scrollable layout.
That is, it would sit on the buttom (like an adview) independent of the scrollable part. I was only able to place it inside the scrollView.
How can I place it below, so it would always visible ?

like image 899
laszlo Avatar asked Nov 30 '11 14:11

laszlo


People also ask

What is nested scroll view?

NestedScrollView is just like ScrollView , but it supports acting as both a nested scrolling parent and child on both new and old versions of Android. Nested scrolling is enabled by default.

How do I set scroll view?

In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it.

What is the difference between ScrollView and horizontal ScrollView?

Attributes Of Scroll View: ScrollView and HorizontalScrollView has same attributes, the only difference is scrollView scroll the child items in vertical direction while horizontal scroll view scroll the child items in horizontal direction.

Can ScrollView be root?

ScrollView as a root layoutA ScrollView can only have a single child, which can be other layouts. It's therefore common for a ScrollView to be the root layout on a page. To scroll its child content, ScrollView computes the difference between the height of its content and its own height.


3 Answers

Use a RelativeLayout, and organize it like this:

<?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:orientation="vertical" >

    <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_centerHorizontal="true"
        android:layout_alignParentTop="true"
        android:layout_above="@+id/linearLayoutThatDoesNotScroll" >

        <LinearLayout
            android:id="@+id/linearLayoutWithLotofContent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >
        </LinearLayout>

    </ScrollView>

    <LinearLayout
        android:id="@+id/linearLayoutThatDoesNotScroll"  
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" >
    </LinearLayout>

</RelativeLayout>

The trick is in the ScrollView placement, at the same time it is aligned with the top of the screen AND above the lower, fixed, LinearLayout. It just works.

like image 134
castle1971 Avatar answered Oct 16 '22 08:10

castle1971


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" >
    <ScrollView android:id="@+id/scroll_view"
        android:layout_width="fill_parent" 
        android:layout_height="0dp"
        android:layout_weight="1" >
        <LinearLayout android:id="@+id/content"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" />
    </ScrollView>
    <LinearLayout android:id="@+id/bottom"
        android:layout_width="fill_parent" 
        android:layout_height="10dip" />          
</LinearLayout>

You will add your bottom content to the bottom linearLayout with the android:id=bottom :)

like image 27
Alioooop Avatar answered Oct 16 '22 07:10

Alioooop


If you used a vertical LinearLayout to hold the scrollable layout, then you could add the adview to the LinearLayout below the scrollable layout and it would appear at the bottom of the screen. (assuming your weights are set correctly,and the scroll layout is set to WRAP_CONTENT)

A RelativeLayout would allow you to set the adview to align itself with the bottom of the scrollable layout as well, but you would still need to make sure the scrollable layout was set to WRAP_CONTENT so it didn't automatically take up the entire screen.

like image 31
Nyth Avatar answered Oct 16 '22 09:10

Nyth