4

I have a problem with my layout, the last linearlayout doesn't seem to expand fully. FYI this is my xml file:

<?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollView1" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/ihealthfirst" android:orientation="vertical" > <include android:layout_width="fill_parent" android:layout_height="match_parent" layout="@layout/tabsfornutrition" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" > <ImageView android:id="@+id/imagefruits" android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/vegetables" android:paddingBottom="15dp" android:paddingLeft="15dp" android:paddingRight="15dp" android:paddingTop="15dp" android:src="@drawable/fruits_logo" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingRight="15dp" android:paddingTop="35dp" > <TextView android:id="@+id/txtApples" style="@style/NutritionText" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_gravity="fill_vertical" android:layout_weight="0.50" /> <Button android:id="@+id/btViewApples" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/viewnutritionalfacts" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_gravity="bottom" > <TextView android:id="@+id/descheader" style="@style/DescriptionHeader" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="15dp" android:paddingRight="15dp" android:text="@string/description" /> <TextView android:id="@+id/fruitDesc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical|right" android:paddingLeft="15dp" android:paddingTop="10dp" /> </LinearLayout> </LinearLayout> </ScrollView> 

enter image description here

If you could help me, I'd appreciate it. Thanks

4
  • TextView android:layout_width="fill_parent" change to wrap_content Commented Dec 4, 2012 at 13:02
  • what textview are u referring to? Commented Dec 4, 2012 at 13:12
  • What is the problem exactly? What is wrong with your screenshot? Commented Dec 4, 2012 at 17:40
  • my last linearlayout is not expanding to its full size. Commented Dec 8, 2012 at 6:04

6 Answers 6

21

Did you try adding android:fillViewport="true" to your ScrollView layout ? (see Romain Guy's trick : http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/ )

Sign up to request clarification or add additional context in comments.

1 Comment

just as the javafx's scrollPane
1

The included tabsfornutrition element has a layout_height of match_parent and it is the first child of its parent, so it will obviously take all available space...

Try setting wrap_content instead, for this element and the one after:

<include android:layout_width="fill_parent" android:layout_height="wrap_content" layout="@layout/tabsfornutrition" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" > 

4 Comments

still the same. My last linearlayout is not expanding. I tried using fillViewport but my last linearlayout has gone out of sight
What do you mean by "not expanding" ? Can you see the 2 text views of the last linear layout when you scroll ?
No i can't see the 2 textviews
Then I don't know what else to try...I just tested it with sample images/text and it works for me
0

I hope u talking about the LinearLayout which has Description, first of all I think u r not clear with fill_parent / match_parent / wrap_content, why I'm thinking like this s,

U r setting height and width as fill_parent for both the include layout and also to the sibling Linearlayout.

<includ android:layout_width="fill_parent" android:layout_height="match_parent" layout="@layout/tabsfornutrition" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" > 

but u not worry about one layout is overlaps another.

So pls go throw following structure, that will give you a clear understating. I hope u need to fill the linearlayout which having the description, if not update your question clearly..

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scrollView1" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/ihealthfirst" android:orientation="vertical" > <include android:layout_width="match_parent" android:layout_height="wrap_content" layout="@layout/tabsfornutrition" /> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" > <ImageView android:id="@+id/imagefruits" android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/vegetables" android:paddingBottom="15dp" android:paddingLeft="15dp" android:paddingRight="15dp" android:paddingTop="15dp" android:src="@drawable/fruits_logo" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingRight="15dp" android:paddingTop="35dp" > <TextView android:id="@+id/txtApples" style="@style/NutritionText" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_gravity="fill_vertical" android:layout_weight="0.50" /> <Button android:id="@+id/btViewApples" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/viewnutritionalfacts" /> </LinearLayout> </LinearLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_gravity="bottom" > <TextView android:id="@+id/descheader" style="@style/DescriptionHeader" android:layout_width="fill_parent" android:layout_height="wrap_content" android:paddingLeft="15dp" android:paddingRight="15dp" android:text="@string/description" /> <TextView android:id="@+id/fruitDesc" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical|right" android:paddingLeft="15dp" android:paddingTop="10dp" /> </LinearLayout> </LinearLayout> </ScrollView> 

2 Comments

If you set match_parent on the first LinearLayout then the it makes no sense to put it in a ScrollView. The whole point of a ScrollView is to wrap a child that is bigger than itself...
so should he leave the ScrollView blank?
0

The LinearLayout (and the textViews) are set to wrap_content. Set the second LinearLayout to:

android:layout_height="match_parent" 

Comments

0

Scrollview for only one child define and first of all u define scrollview and then define relative layout and then whatever your require for layouts using.

Comments

-2

It's because you tell it to wrap_content in height. It should be match_parent.

1 Comment

what linearlayot are u referring to?