ScrollView don't scroll? - android

I've a ScrollView / RelativeLayout / FrameLayout and I inside put programmaticaly some widgets.
Here is the gui xml :
<?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"
android:fillViewport="true"
android:background="#drawable/fond_app">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<TextView
android:id="#+id/titreAppli"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="My Big Application"
android:textStyle="bold"
android:textColor="#9b9b71"
android:textSize="15dp"
/>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/out"
android:layout_below="#id/titreAppli"
/>
</RelativeLayout>
</ScrollView>
In the FrameLayout, I put programaticaly another RelativeLayout, and other widgets inside.
With some widgets (text, image, buttons), I can't scroll. With other (a linearlist with text), I can scroll.
Why ? Is there a solution ?
Thanks.

First remove frame layout. You should use some other layout like relative instead of framelayout. Becasue Framelayout is not expanding and there fore scroll view is not working. If you use linear or relative then they will expand and you will be able to scroll.

Have you tried without the android:fillViewport="true" ?

Related

2 RelativeLayouts in one layout

I've decided to use 2 RelativeLayouts for my app, one Layout for one portion of child Views on the screen to the left, the other for child Views to go to the right.
The problem is I don't know how to lay them out in XML so that the middle white space isn't included when I inflate my Layout.
This is what I want.
When I use 1 RelativeLayout, the middle white space is filled with the RelativeLayout, and I can't touch anything behind it.
Thank you very much for reading.
Do something similar to the following example.
This will create a LinearLayout with 2 RelativeLayouts using layout_weight to space the RelativeLayouts and then you can populate the RelativeLayouts with whatever you want.
The Buttons are just place holders for the example.
<?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="horizontal" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST2" />
</RelativeLayout>
</LinearLayout>

Android: How do I add a footer to a fullscreen scrollview?

I want the footer to be anchored at the bottom of the screen if and only if it can be anchored there without overlapping any other views.
The problem is that I don't know how many views are going to be added to the header or the footer.
If putting the footer at the bottom of the window would make it overlap, I want to put the footer at the bottom of the scrollview. (Maybe by adding it to the RelativeLayout with the rule that it needs to be below the top component?)
Here is a pic of what I'm trying to get:
desired result
Where:
1)The RelativeLayout contains both the TableLayout at the top, and the LinearLayout at the bottom.
2)The TableLayout expands downwards as TableRows get added to it.
3)The LinearLayout expands up from the bottom as views get added to it.
~~~
I'd like for the scrollview to grow in size only enough to fit the components without overlapping.
Thanks in advance for such awesome community support
I think you can solve it in linear layout. You set three blocks in linear layout: header, body, footer. Set body to fill_parent and layout_weight=1, this way body will expand to fill what left after header and footer taken its part from parent. Whole structure place into ScrollView.
<?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"
android:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow><TextView android:text="Text1"/></TableRow>
<TableRow><TextView android:text="Text2"/></TableRow>
</TableLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="#string/lorem_ipsum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="Text3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="Text4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
I tested this in Emulator of Android 2.1 and it looks it works.

how to make a linear layout horizontall scrollable

My application containing different layouts.one of them is a linear layout.it's content is dynamically adding.i want to make this layout horizontally scrollable.for this i have put my layout in a scroll view.but still it s not scrolling...given below is my code
<LinearLayout android:id="#+id/scoreballparent_layout"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_above="#+id/score_layout">
<ScrollView android:layout_height="wrap_content"
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
>
<LinearLayout android:layout_width="fill_parent"
android:id="#+id/scoreball_layout"
android:layout_height="wrap_content"
android:isScrollContainer="true"
android:scrollbars="horizontal">
</LinearLayout>
</ScrollView>
</LinearLayout>
Use HorizontalScrollView instead
Also your layout will become scrollabe after its contect can't fit layout area.
Simply use this in xml
android:fadeScrollbars="true" may be it works for you

LinearLayout problem

I have this code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layoutAnim"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/leftCornerImage"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
<ImageButton
android:id="#+id/btnNight"
android:layout_width="62px"
android:layout_height="62px" />
<ImageButton
android:id="#+id/btnAlarm"
android:layout_width="62px"
android:layout_height="62px" />
<ImageButton
android:id="#+id/btnThermo"
android:layout_width="62px"
android:layout_height="62px"
android:layout_gravity="bottom" />
<ImageButton
android:id="#+id/btnDigital"
android:layout_width="62px"
android:layout_height="62px"
android:layout_gravity="bottom" />
</LinearLayout>
<LinearLayout .....
</LinearLayout>
</LinearLayout>
Can somebody helps me. Why android:layout_gravity="bottom" doesn't work? If you have the better solution, please help me.
A vertical LinearLayout will only honor horizontal gravity; a horizontal LinearLayout will only honor vertical gravity. Use RelativeLayout, or else use android:layout_weight to distribute extra vertical space where you want it.
android:layout_gravity="bottom" here goes for text inside button.
If you want buttons anchered to the bottom, you should provide android:gravity="bottom"> to first inner LinearLayout.
The parent controls the gravity so android:gravity="bottom" should be in the containing linear layout instead. Note this will affect all of the views. If you want only the last view to hug the bottom, either use a RelativeLayout or place a plain view in between the two images and set its layout_weight to 1.
Hope this helps!

Setting footer to ListView

everyone.
Can you help me with setting footer to ListView? I've described footer in layouts, and then:
View footer = getLayoutInflater().inflate(R.layout.bottom, getListView(), false);
getListView().addFooterView(footer);
But it didn't appear... Can you give an example? Also I need to set the height of footer dynamically. Here is the code of footer:
<?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:background="#87ceeb"
>
<TextView android:id="#+id/loading"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#000000"
android:textStyle="bold"
android:text="Loading..."/>
</LinearLayout>
There can be few reasons for this,
Have you added your code
getListView().addFooterView(footer); before the setAdapter of ListView ? If yes.
There might be problem in xml layout,
If your listview is wrap_content and your footerlayout has fill_parent , Footer might not appear unless some text is there in your textview of footer layout.
Change the listview layout_width="fill_parent" and footer layout's layout_width="fill_parent"
To quickly check , give a background color to your footer layout and see its placement.
Hope it helps.
The best way to do this is with RelativeLayout.
1) Create a RelativeLayout for the whole layout.
2) Create two views, perhaps ListView and LinearLayout for the footer.
3) Make the listView aligned to the parent top with a bottom margin equal to the height of the footer view or linear layout.
4) make the linear layout aligned the parent bottom
Done. Hope this helps.
EDIT:
Some quick code to try and get the point across:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent" >
<ListView
android:id="#+id/list"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_marginBottom="50dp"
android:layout_alignParentTop="true" />
<TextView
android:text="Some text"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true" />
</RelativeLayout>

Categories

Resources