Placing A ListView Below Other View in Android - android

I have been trying to Place A listview under some otherviews in Android.
For Example.
I have a Scrollview which I Place Other View Inside Including The ListView
I Want the List View to be Long as Long As 1000dp so that User can Scroll to the Listview and the Scroll the List Inside a Layout.
I have been on this for 2 days. Any Help will be highly appreciated.
This is My Code
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:fillViewport="true" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="50dip"
>
<TextView
android:id="#+id/tvheading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginTop="2dp"
android:gravity="center"
android:text="#string/title_AllSensorhead"
android:textStyle="bold" />
<View
style="#style/Divider"
android:layout_above="#+id/listView" />
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center_horizontal"
android:indeterminateDrawable="#drawable/progress"
android:visibility="gone" />
<com.github.mikephil.charting.charts.PieChart
android:id="#+id/chart"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimaryDark"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:id="#+id/textSensorName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="2dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textSensorNo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textSize="15dp"
android:textStyle="bold" />
</LinearLayout>
<ListView
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="1000dip"
android:layout_marginTop="5dip"
>
</ListView>
</LinearLayout>

Use a scroll view to enclose all the android xml file....the defining layout should be scrollable instead of linear layout....

there can be one possible solution for your problem..
As far i guess you just want to scroll whole screen that have a listview..
So, First create a different layout name like header_listview.xml
in that put your code apart of that listview in it..
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="50dip"
>
<TextView
android:id="#+id/tvheading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:layout_marginTop="2dp"
android:gravity="center"
android:text="#string/title_AllSensorhead"
android:textStyle="bold" />
<View
style="#style/Divider"
android:layout_above="#+id/listView" />
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center_horizontal"
android:indeterminateDrawable="#drawable/progress"
android:visibility="gone" />
<com.github.mikephil.charting.charts.PieChart
android:id="#+id/chart"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimaryDark"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:id="#+id/textSensorName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="2dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textSensorNo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="2dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/white"
android:textSize="15dp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
Now your listview layout can be simply like
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/listView"
android:layout_width="match_parent"
android:layout_height="1000dip"
android:layout_marginTop="5dip"
/>
In your java file when fatching the instance of list..
Add two line there
View headerView= LayoutInflater.from(this).inflate(R.layout.header_listview,null,false);
listView.addHeaderView(headerView;
You can get those TextViews & progressbar & chart from this headerview..like
TextView txt=(TextView) headerView.findViewById(R.id.tvheading);
from this approach the violation of scrollview with listivew wont be arrive,
Also you dont need to give 1000dip fix height to listview..
Please tell if need more assistance..
And appreciate if it helps ..

Related

Android dialog with ListView

I have a problem with a dialog with some buttons and a ListView.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"
android:orientation="vertical"
tools:context=".MyApplicationActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/selectContactRecord"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" />
<Button
android:id="#+id/btnContactPickerAdd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:drawableLeft="#android:drawable/ic_menu_add"
android:drawableStart="#android:drawable/ic_menu_add"
android:text="#string/noContact" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:text="#string/selectBulbs"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" />
<ListView
android:id="#+id/listViewCallRecordsDetail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#drawable/gradient"
tools:listitem="#layout/callrecord_detail_list_item" >
</ListView>
<Button
android:id="#+id/btnTestAddRecord"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:drawableLeft="#drawable/test_bulbs"
android:drawableStart="#drawable/test_bulbs"
android:text="#string/test" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:background="#android:color/black"
android:orientation="horizontal" >
<Button
android:id="#+id/btnCancelAddRecord"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="#android:drawable/ic_menu_revert"
android:drawableStart="#android:drawable/ic_menu_revert"
android:text="#string/cancel" />
<Button
android:id="#+id/btnSaveAddRecord"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableLeft="#android:drawable/ic_menu_save"
android:drawableStart="#android:drawable/ic_menu_save"
android:text="#string/save" />
</LinearLayout>
The problem is now, if I have a lot of records in the ListView, the button below disappears and it is not possible to scroll down.
I tried this with a ScrollView, but failed because it is not possible to use that with a ListView.
I want that the buttons below the listview always stay at the bottom and that the ListView is scrollable.
Can somebody please give me a hint?
Change your list view to this:
<ListView
android:id="#+id/listViewCallRecordsDetail"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:divider="#drawable/gradient"
tools:listitem="#layout/callrecord_detail_list_item"
It'll make sure the button is layout in the bottom and, the list view take all the height remain
You want this :
I want that the buttons below the listview always stay at the bottom
and that the ListView is scrollable.
For this change this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black">
<TextView
android:id="#+id/tvContactRecord"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="#string/selectContactRecord"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white" />
<Button
android:id="#+id/btnContactPickerAdd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:drawableLeft="#android:drawable/ic_menu_add"
android:drawableStart="#android:drawable/ic_menu_add"
android:text="#string/noContact"
android:layout_below="#+id/tvContactRecord" />
<TextView
android:id="#+id/tvSelectBulbs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:text="#string/selectBulbs"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#android:color/white"
android:layout_below="#+id/btnContactPickerAdd" />
<ListView
android:id="#+id/listViewCallRecordsDetail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#drawable/gradient"
tools:listitem="#layout/callrecord_detail_list_item"
android:layout_below="#+id/tvSelectBulbs"
android:layout_above="#+id/btnTestAddRecord" >
</ListView>
<Button
android:id="#+id/btnTestAddRecord"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="15dp"
android:drawableLeft="#drawable/test_bulbs"
android:drawableStart="#drawable/test_bulbs"
android:text="#string/test"
android:layout_above="#+id/llBottom" />
<LinearLayout
android:id="#+id/llBottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="5dp"
android:background="#android:color/black"
android:orientation="horizontal"
android:layout_alignParentBottom="true" >
<Button
android:id="#+id/btnCancelAddRecord"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawableLeft="#android:drawable/ic_menu_revert"
android:drawableStart="#android:drawable/ic_menu_revert"
android:text="#string/cancel" />
<Button
android:id="#+id/btnSaveAddRecord"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableLeft="#android:drawable/ic_menu_save"
android:drawableStart="#android:drawable/ic_menu_save"
android:text="#string/save" />
</LinearLayout>
</RelativeLayout>
You can consider below layout for the solution. You can replace Buttons as per your need.(I have given 2 buttons to simplify the things for you) Also you can also consider taking the buttons in another layout as well if required.
<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"
tools:context="${relativePackage}.${activityClass}" >
<Button
android:id="#+id/btn2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="My Button 2" />
<Button
android:id="#+id/btn1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/btn2"
android:text="My Button 1" />
<ListView
android:id="#+id/lstMyListView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#id/btn1" />
</RelativeLayout>

ScrollView and ListView android

I have a problem with a scrollView and a listView in android.
My Scrollview does not work. The last item does not appear and the listView take the whole screen.
I don't know why and i have not found any answer yet.
My xml file :
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/additionName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="Your Order"
android:textSize="30dp" />
<ListView
android:id="#+id/additionListviewProducts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/additionName"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:isScrollContainer="false"/>
<View
android:id="#+id/additionLineSeparator"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="#+id/additionListviewProducts"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#000000" />
<TextView
android:id="#+id/additionTotal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/additionLineSeparator"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:gravity="right"
android:text="100 euros"
android:textSize="20sp" />
<Button
android:id="#+id/validatePayment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/additionTotal"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#drawable/button_style"
android:text="Order"
android:textSize="25sp" />
</LinearLayout>
</ScrollView>
Putting a ListView inside ScrollView without breaking the ScrollView is not naturally possible. The easy way to make it happen anyway is to disable the ListView view recycling functionality, which will affect performance. If you still need it (there are some use cases), see this answer: How can I put a ListView into a ScrollView without it collapsing?
Put your whole ScrollView in RelativeLayout with android:orientation="vertical". Thanks!
Try this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1212"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/additionName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text="Your Order"
android:textSize="30dp" />
<ListView
android:id="#+id/additionListviewProducts"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/additionName"
android:layout_marginBottom="10dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="10dp"
android:isScrollContainer="false"/>
<View
android:id="#+id/additionLineSeparator"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_below="#+id/additionListviewProducts"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#000000" />
<TextView
android:id="#+id/additionTotal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/additionLineSeparator"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:gravity="right"
android:text="100 euros"
android:textSize="20sp" />
<Button
android:id="#+id/validatePayment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/additionTotal"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#drawable/button_style"
android:text="Order"
android:textSize="25sp" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
Hope this may help you!

HorizontalScrollView - how to move one item at a time

I'm working with an horizontal scroll view composed of a maximum number of 10 Network Image View, added programmatically to the horizontal scroll view.
The problem I'm trying to figure out is simple.
My objective is to show one image at a time when the user scrolls the view.
Basically, I'd like to realize a slideshow similar to the app "AutoScout24".
I tried to add a Scroll Listener, but it doesn't behave as I wanted.
Thank you for your help.
If you need it, I may post the code of the listener.
EDIT:
That's the XML code, using the ViewPager.
I can't understand why if I put it inside a ScrollView, it shows nothing.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AppInfo"
android:padding="5dp"
android:id="#+id/bread" />
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/image_pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#ffffffff"
android:gravity="fill_horizontal"
android:layout_gravity="top"
android:id="#+id/attivita_linear"
android:padding="10dp"
android:isScrollContainer="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nome Attività"
android:id="#+id/textView_nome"
android:layout_gravity="center_vertical|center_horizontal"
android:textSize="30sp"
android:paddingBottom="35dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Indirizzo: "
android:id="#+id/textView_indirizzo"
android:textSize="20sp"
android:textIsSelectable="false"
android:paddingBottom="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Telefono: "
android:id="#+id/textView_tel"
android:textSize="20sp"
android:textIsSelectable="false"
android:paddingBottom="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email: "
android:id="#+id/textView_email"
android:textSize="20sp"
android:textIsSelectable="false"
android:paddingBottom="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="www: "
android:id="#+id/textView_www"
android:textSize="20sp"
android:textIsSelectable="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Descrizione: "
android:id="#+id/textView_descrizione"
android:textSize="20sp"
android:textIsSelectable="false" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="right"
android:layout_gravity="center"
android:id="#+id/attivita_buttons"
android:padding="5dp"
android:isScrollContainer="true">
<ImageButton
android:id="#+id/image_button_call"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/ic_action_call"
android:paddingRight="15dp"
/>
<ImageButton
android:id="#+id/image_button_share"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/ic_action_share"
android:paddingRight="5dp"
/>
<!-- TODO implement Calendar button
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_call"/>
-->
</LinearLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#+id/footer"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#drawable/cola">
</FrameLayout>
</RelativeLayout>
</LinearLayout>
Problem solved.
I decided to implement a ViewPager instead of HorizontalScrollView.
Thanks to the ImageAdapter, handling the scroll moves is

Showing ListView outside ScrollView android

I have a particular LinearLayout where I have multiple components. I have a ScrollView in which I have another LinearLayout with a ImageView, two TextViews and Buttons. I also have a ListView at the very bottom of the page which shows comments. The problem is I want the ListView to show completely without any scrolling. The ListView scrolls giving a bad design. If I place the ListView outside the ScrollView, it does not show.
Here is my code:-
details.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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="38.7dp"
android:background="#FF3C6FA6"
android:minHeight="25px"
android:minWidth="25px"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/imageBackBtn"
android:layout_width="35dp"
android:layout_height="35dp"
android:background="#FF3C6FA6"
android:fadingEdge="none"
android:src="#drawable/btnbackclickedxml" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- Main vertical LinearLayout-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/layoutList">
<TextView
android:id="#+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:padding="10dp"
android:text="Large Text"
android:textAlignment="center"
android:textAppearance="?android:attr/textAppearanceLarge" />
<!-- Layout for Date, Likes, comments and views -->
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="98dp"
android:layout_height="wrap_content"
android:background="#drawable/rounded_corner" >
<TextView
android:id="#+id/txtPubDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#F8F8F8"
android:textSize="11sp"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<ImageButton
android:id="#+id/btnViews"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_marginLeft="20dp"
android:background="#color/white"
android:src="#drawable/btnviewpressed" />
<TextView
android:id="#+id/txtViews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="view"
android:textColor="#FF3C6FA6"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageButton
android:id="#+id/btnComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/white"
android:layout_marginLeft="20dp"
android:src="#drawable/btncommentpressed"/>
<TextView
android:id="#+id/txtComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:textColor="#FF3C6FA6"
android:text="view"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<ImageView
android:id="#+id/imgNewsImage"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/abc" />
<TextView
android:id="#+id/txtBody"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Small Text"
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/btnComms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comments" />
<Button
android:id="#+id/btnAddComms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Comments" />
</LinearLayout>
<ListView
android:id="#+id/android:list"
android:visibility="invisible"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/getdata"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:layout_gravity="bottom"
android:listSelector="#drawable/list_selector"
android:padding="5dp"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Take scrollview and Listview inside a one parent LinearLayout and assign weight for both , this may help you..
As per sending code in your problem you have used scroll view height with match_parent. To resolve this you have to set fixed height in your xml file or in your java file by get reference of your scroll view

ListView and LinearLayout overLapping

I have layout like this
At the top i have listView ,below that i have LinearLayout (the one with radio button Add New Addess).
Now Issue is my listView and linearlayout are overlapping . Kindly help me .
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1.0" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="63dp"
android:layout_weight="0.05" >
<ImageView
android:id="#+id/menu_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/hs18_logo" />
<ImageView
android:id="#+id/setting_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="17dp"
android:scaleType="fitCenter"
android:src="#drawable/menu" />
<ImageButton
android:id="#+id/signin_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/setting_icon"
android:layout_marginRight="20dp"
android:background="#android:color/transparent"
android:src="#drawable/signin"
android:visibility="invisible" />
</RelativeLayout>
<TextView
android:id="#+id/cart_checkout_title"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:background="#color/gray"
android:gravity="center"
android:text="Shipping Address"
android:textStyle="bold" />
<ListView
android:id="#+id/shipping_addresses_listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.90" >
</ListView>
<include layout="#layout/shipping_add_adresss" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_weight="0.05"
android:gravity="center" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buttonshape_white"
android:text="Cancel"
android:textColor="#color/red" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#drawable/buttonshape_red"
android:text="Update Shipping Address"
android:textColor="#color/white" />
</LinearLayout>
</LinearLayout></ScrollView>
#MohitSharma Always remember
Never use a ListView in a ScrollView
for reasons check this:
ListView inside ScrollView is not scrolling on Android
What ever the requirement is you can do it by using just one of them(ListView or ScrollView).
So, for your case you can do either of the 2 things below:
Have only ListView in your Layout.xml and you can set that huge
layout as a FooterView to your ListView.
If you want to use a ScrollView, remove the ListView and dynamically
add those List Items as normal Layouts(Linear/RelativeLayout).
first approach is more recommended.
use layout_above property for listview.
android:layout_above="#+id/linear_layout"
Try this work for you i have checked it.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scrollbars="vertical"
>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="5dp">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="63dp">
<ImageView
android:id="#+id/menu_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/hs18_logo" />
<ImageView
android:id="#+id/setting_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="17dp"
android:scaleType="fitCenter"
android:src="#drawable/menu" />
<ImageButton
android:id="#+id/signin_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/setting_icon"
android:layout_marginRight="20dp"
android:background="#android:color/transparent"
android:src="#drawable/signin"
android:visibility="invisible" />
</RelativeLayout>
<TextView
android:id="#+id/cart_checkout_title"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:background="#color/gray"
android:gravity="center"
android:text="Shipping Address"
android:textStyle="bold" />
<ListView
android:id="#+id/shipping_addresses_listView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
>
</ListView>
</LinearLayout>
</ScrollView>
& if you Add Layout After Listview Give id to scrollview & add Layout in Scrollview this is perfectly work for you.

Categories

Resources