Android TextView Text wont wrap on Listview - android

hello i am trying to wrap a textview that has a long text. but when i test it, it just goes beyond the screen. What im trying to do is it will go to the next line if the text is long and it automatically adjust the layout. I am using this in a listview.
i am referring to this old question Android TextView Text not getting wrapped, it works on him so i tried to implement it but it wont effect on mine. thanks for answering.
here's my XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:background="#e6e6e6"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:padding="4dip"
android:layout_weight="1">
<TextView
android:id="#+id/tv_reviewer_name"
android:textSize="16sp"
android:textAppearance="?android:textAppearanceLarge"
android:text="Reviewer Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_marginTop="5dp"
android:id="#+id/tv_review_details"
android:textSize="16sp"
android:textAppearance="?android:textAppearanceSmall"
android:text="Review"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:width="0dip"/>
</LinearLayout>
</LinearLayout>
UPDATE
here's my listview:
<ListView
android:divider="#android:color/transparent"
android:dividerHeight="2.0sp"
android:id="#+id/lv_reviews"
android:background="#f2f2f2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

You can use the inputType to auto manage a multiline text.
<TextView
android:layout_marginTop="5dp"
android:id="#+id/tv_review_details"
android:textSize="16sp"
android:textAppearance="?android:textAppearanceSmall"
android:text="Review"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:width="0dip"
android:inputType="textMultiLine"
/>

if i use listView or recyclerView, i well put the layout width match parent as mentioned below:
<LinearLayout
<!--change to match_parent-->
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" android:padding="4dip"
android:layout_weight="1">
try it once, hope this will help you.

problem solved. it turns out android studio didnt update my changes when i ran my app. i uninstalled the app and then run it again and it works perfectly.

When you are using Gravity in vertical orientation, you have to use layout_height=0dp & when you are using Gravity in Horizontal orientation then you have to use layout_width=0dp for every child of Linear Layout so that it can resize the layout by itself
<LinearLayout
android:background="#e6e6e6"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<LinearLayout
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" android:padding="4dip"
android:layout_weight="1">
<TextView
android:id="#+id/tv_reviewer_name"
android:textSize="16sp"
android:textAppearance="?android:textAppearanceLarge"
android:text="Reviewer Name"
android:layout_width="wrap_content"
android:layout_height="0dp" />
<TextView
android:layout_marginTop="5dp"
android:id="#+id/tv_review_details"
android:textSize="16sp"
android:textAppearance="?android:textAppearanceSmall"
android:text="Review"
android:layout_height="0dp"
android:layout_width="match_parent"/>
</LinearLayout>
</LinearLayout>

Related

How to make a "subLayout" fixed in Android

I'm creating an app that gets some values, you click in a button and it returns some other values and this views are distributed in 2 subLayouts of a bigger vertical LinearLayout 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="match_parent"
android:layout_height="match_parent"
android:padding="10dp">
<RelativeLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="0.4">
<EditText
android:layout_width="70dp"
android:layout_height="wrap_content"
android:inputType="number"
android:id="#+id/number1" />
<EditText
android:layout_width="70dp"
android:layout_height="wrap_content"
android:inputType="number"
android:id="#+id/number2"
android:layout_below="#+id/number1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calc!"
android:id="#+id/calcButton"
android:layout_below="#+id/number2"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal"
android:layout_weight="0.6"
android:layout_alignParentBottom="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Answer"
android:id="#+id/Answer" />
</RelativeLayout>
</LinearLayout>
My problem is that when I click on my EditText and the keyboard appears the answer's TextView goes up with the keyboard and "overrides" my button (the entire RelativeLayout follows the keyboard), there's a way of setting the RelativeLayout fixed so that it stays where it is mean to be?
Here what is happening:
There's a way of fixing that RelativeLayout?
Try setting android:windowSoftInputMode="adjustPan" for the activity in Android Manifest file.

How would I use a ScrollView inside a FrameLayout?

I'm having a lot of trouble getting my ScrollView to function properly. I'm using a Master-Detail design. The Master scrolls, since it's a listView. The Detail when selected will display the scrollbar implemented in my XML for a couple seconds when the Activity is inflated before disappearing (Stackoverflow won't allow me to post the screenshot of the error since this is my first post)
When I try to scroll the Detail Activity with touch input nothing happens. I've tried copying and pasting Mel's solution to what seems like an identical problem in the post at ScrollView doesn't work. I've also tried every conceivable combination of match_parent and fill_parent for the parent, child, and ScrollView itself. Any help is appreciated. My XML code is below:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/item_detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ItemDetailActivity"
tools:ignore="MergeRootFrame">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fillViewport="true"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/linearLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:layout_marginTop="20dp"
android:stretchColumns="1, 2"
>
<ImageView
android:id="#+id/picture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:src="#drawable/bmp1"
android:layout_alignParentTop="true"
/>
<TableLayout
android:id="#+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_marginTop="20dp"
android:stretchColumns="1, 2">
<!-- Table Row 0 -->
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/tableRow0">
<TextView
android:id="#+id/priWeapon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/priWeapon" android:textColor="#000" android:textStyle="bold"
android:gravity="left"
android:padding="5dp"/>
<EditText
android:id="#+id/priWeaponEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/NA" android:textSize="14sp" android:textStyle="bold"
android:gravity="center"
android:focusable="false"
android:layout_weight="1"
android:cursorVisible="false"
android:longClickable="false"/>
</TableRow>
<!-- Table Row 1 -->
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/tableRow1">
<TextView
android:id="#+id/priWeaponRange"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/priMaxRange" android:textColor="#000"
android:gravity="left"
android:padding="5dp"/>
<EditText
android:id="#+id/priWeaponRangeEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/NA" android:textSize="14sp"
android:gravity="center"
android:focusable="false"
android:layout_weight="1"
android:cursorVisible="false"
android:longClickable="false"/>
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>
I found a solution! Instead of trying to apply the formatting to the Activity XML itself, I cut and pasted it into one of the Activity's Fragment XMLs, which didn't have a frameLayout. Because of this change it now scrolls perfectly while maintaining the title bar on top throughout the scroll, exactly the behavior that I wanted. I've posted the final code below. If you have a solution that would still allow me to use a scrollView inside a FrameLayout though I'd be more than happy to see it for future reference. Thank you for your help!
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fillViewport="true"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/linearLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:layout_marginTop="20dp"
android:stretchColumns="1, 2"
>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/item_detail"
style="?android:attr/textAppearanceLarge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textIsSelectable="true"
tools:context=".ItemDetailFragment"/>
<ImageView
android:id="#+id/picture"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:src="#drawable/bmp1"
android:layout_alignParentTop="true"
/>
<TableLayout
android:id="#+id/tableLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_marginTop="20dp"
android:stretchColumns="1, 2">
<!-- Table Row 0 -->
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/tableRow0">
<TextView
android:id="#+id/priWeapon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/priWeapon" android:textColor="#000" android:textStyle="bold"
android:gravity="left"
android:padding="5dp"/>
<EditText
android:id="#+id/priWeaponEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/NA" android:textSize="14sp" android:textStyle="bold"
android:gravity="center"
android:focusable="false"
android:layout_weight="1"
android:cursorVisible="false"
android:longClickable="false"/>
</TableRow>
</TableLayout>
</LinearLayout>
</ScrollView>
Your goal is to use the maximal screen size for the ImageView and then scroll down to the (at first invisible) TableLayout? Thats afaik not possible. When you set android:layout_height="fill_parent" on ImageView it uses the the maximum possible (in your example all of the screen size) space. So no TableLayout is rendered and there is no need for scrolling. You should set the android:layout_height="wrap_content" in the ImageView.
Some notes on the source code:
Use match_parent instead of fill_parent. It's renamed since API Level 8
You have a useless android:layout_below="#id/picture" in the TableLayout. May an artifact from a previous version with RelativeLayout?
Remove the namespace definitions in the TableLayout

Swiperefreshlayout with fragment not scrolling up

I have a layout with some preferences. It works correctly in portrait, but not in landscape. I want this layout to refresh with a swiperefreshlayout, and does work. But as i i say in the title, it doesnt scroll up.
Ive been playing with a normal LinearLayout, with a RelativeLayout, using the swiperefreshlayout as the root view, playing with weights, ... but nothing. It either doesnt scroll up, or doesnt show the preferences correctly (only the 1st title). Dont know what else to try.
I should also say, i want this screen to keep a linearlayout at the bottom, fixed there. So, only the preferences would scroll.
Heres what i have right now:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/edittexts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:elevation="8dp"
android:background="#color/primary"
android:visibility="gone"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/setwallpaperbutton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="onActivarClick"
android:text="#string/setwallpaperbuton"
android:visibility="gone"
android:clickable="true"
android:enabled="true"/>
<EditText
android:id="#+id/edittextlocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="2dp"
android:textColor="#android:color/white"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:layout_gravity="center"
android:inputType="textMultiLine"
android:maxLines="2"
android:background="#android:color/transparent"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/edittextupdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_margin="2dp"
android:textColor="#android:color/white"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:layout_gravity="center"
android:inputType="text"
android:background="#android:color/transparent"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/swipelayout"
android:isScrollContainer="true"
android:layout_alignParentTop="true"
android:layout_above="#+id/edittexts">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true">
<fragment
android:name="es.jnsoft.nowweather.PreferencesFragment"
android:id="#+id/preferencesfragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="#xml/settings"/>
</ScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
Thanks in advance.
According to the documentation,
[SwipeRefreshLayout] should be made the parent of the view that will be
refreshed as a result of the gesture and can only support one direct
child.
This clause is violated in your layout.

ScrollView doesn't work in Android Layout

I designed a simple layout for my test App, a TextView, then a ImageView and a TextView. But the second TextView I want it scrollable (by touch).
I have searched and tried many solutions on the net but still can't make it work.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:scrollbars="vertical"
tools:context=".MainActivity" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="#string/title"
android:textSize="40sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:contentDescription="#string/ada_lovelace"
android:paddingTop="8dp"
android:src="#drawable/ada_lovelace" />
<ScrollView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:id="#+id/scroll1"
android:layout_below="#id/imageView1">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:text="#string/hello_world"
android:textSize="22sp" />
</ScrollView>
</RelativeLayout>
Please help me.
You can use this link. And the format of using scrollview in xml is below:
<linearlayout>
<scrollview>
<linear>or <relativelayout>
</linear layout>
</scrollview>
</linear layout>.
Scrolling works only when a part of its child is not visible in the screen due to large size or large numbers
I had the same problem some weeks ago, and this was my solution:
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RelativeLayout
android:id="#+id/RelativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/textview" />
</RelativeLayout>
</ScrollView>
But if there is not "enough" content in the TextView, it is not scrollable. Only if its more than your screen kann "capture".
Everything works fine after I re-import my project. I don't know what error is this but maybe it's because of eclipse faulty.
Instead of using ScrollView for your TextView, you can make you TextView scrollable using the following code.
<TextView
android:id="#+id/txtView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="5"
android:scrollbars="vertical"
android:textAppearance="?android:attr/textAppearanceSmall" />
And in you Java file use this code
txtView.setMovementMethod(new ScrollingMovementMethod());
Hope this will help.
You don't need a ScrollView for the TextView, TextView has the scrolling attribute.
Try setting it and see whether it works.
Set the ScrollView's height to 38dp.
Set the TextView's size to 40sp.
Then you can scroll the TextView.
Scrollable becomes only the part which is in between ScrollView
So if you want to scroll everything (And as I understood you do) you just need to change the sequence.
I also believe that ScrollView needs to be in layout and have a layout, so you need two layouts: one inside and one out side.Though I'm not sure about last sentence - I'm just starting to learn stuff
Here is your solution implement this code and run the code textview is scrollable.
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:contentDescription="#string/ada_lovelace"
android:paddingTop="8dp"
android:src="#drawable/ada_lovelace" />
<ScrollView
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:id="#+id/scroll1"
android:layout_below="#id/imageView1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="8dp"
android:text="#string/hello_world"
android:textSize="22sp" />
</RelativeLayout>
</ScrollView>
It should work please try
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding_bottom = "10dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/textview" />
</ScrollView>

ListView inside LinearLayout breaking out (Android)

Been struggling with this for a while now. I have a layout XML consisting of various LinearLayouts, with separate weighting. The end result looks like this..
Dont mind the colors, its just to see the break points..Anyway, below the Terminal/Origin etc LinearLayout is a ListView which is populated using a custom adapter. The data loads fine, but then the listView "breaks out" of the LinearLayout, and takes up most of the page
(Dont mind the colors, its just to see the break points..)
ie. it flows over the View above and below.
My XML is as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:ignore="HardcodedText" >
<RelativeLayout
android:id="#+id/navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:background="#FF0000"
android:gravity="right" >
<Button
android:id="#+id/update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:onClick="getFlightInfo"
android:text="Refresh" />
</RelativeLayout>
<LinearLayout
android:id="#+id/table_header"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="0.4"
android:background="#FFFFFF"
android:weightSum="1" >
<TextView
android:id="#+id/header_cell1"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="#string/cell_1_weight"
android:gravity="center_vertical"
android:paddingLeft="5dp"
android:paddingRight="12dp"
android:text="#string/table_header_terminal"
android:textSize="11dp" />
<TextView
android:id="#+id/header_cell2"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="#string/cell_2_weight"
android:gravity="center_vertical"
android:paddingRight="12dp"
android:text="#string/table_header_origin"
android:textSize="11dp" />
<TextView
android:id="#+id/header_cell3"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="#string/cell_3_weight"
android:gravity="center_vertical"
android:paddingRight="12dp"
android:text="#string/table_header_flight"
android:textSize="11dp" />
<TextView
android:id="#+id/header_cell4"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="#string/cell_4_weight"
android:gravity="center_vertical"
android:paddingRight="12dp"
android:text="#string/table_header_scheduled"
android:textSize="11dp" />
<TextView
android:id="#+id/header_cell5"
android:layout_width="0px"
android:layout_height="fill_parent"
android:layout_weight="#string/cell_5_weight"
android:gravity="center_vertical"
android:paddingRight="12dp"
android:text="#string/table_header_status"
android:textSize="11dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/table_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:background="#FFFFFF"
android:orientation="vertical" >
<ListView
android:id="#+id/list_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/filter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#00FF00" />
</LinearLayout>
I may be missing something glaring, but for the life of me, I cant see it. Can anyone help?
Thanks a million..
This is because you have kept LinearLayout's height(the one wrapping listview) "wrap_content".Fixing its size to some dip would solve your problem.
Also make listview's height "fill_parent" then.
EDIT :
try this way:
...
<ListView
android:id="#+id/list_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</ListView>
in upper two layouts,you user 0.2 and 0.4 as weight but in lower two layouts,you users 3 and 1...try it former way and see,if it can help you.also try making height of LinearLayout(the one wrapping listview) to 0dip.
Maybe it is late, but I could help someone.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff0000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="Content 1" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#00ff00">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="Content 2" />
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/linearLayout2"
android:layout_below="#id/linearLayout1"
android:background="#00f0f0"></ListView>
Result:
Ok.. after consulting this post I came up with a fix
Remove the LinearLayout outside the ListView, its superfluous.
Add a height of '0px' (which I've found around the web) to the ListView ensures it obeys the android:weight parameter properly.
Hope this helps.
Remove the weight of id/filter.
Let the ListView have a weight of 1 with fill_parent height.
Remove the listView's immediate parent.
One other thing you missed, is to set the weightSum=sum_of all_child_weight in your root. That should fix the problem.

Categories

Resources