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.
Related
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 ..
i am creating a custom dropdown,where custom dropdown is created using relative layout and listview, on click of relative layout i am making listview to visible and gone, so like this there are many dropdowns vertically one after the other. Without putting scrollview it works fine, Here the problem is if i apply scrollview to whole layout dropdown(which is made using listview) will take only some space and inside the listview itself it enables scroll inside that some space. But i want it to appear as it is without scrolling listview. How could i do this.Any help and suggestion are welcomed.
without scroll view
with scroll view
here i want it to appaer as in without scrollview image ,even if i apply scroll view to whole layout(here whole layout contains number of dropdowns as in figure.)
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:id="#+id/layoutView"
android:background="#drawable/customborder">
<LinearLayout
android:layout_centerVertical="true"
android:id="#+id/Text"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dip">
<TextView
android:id="#+id/viewtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-Select-"
android:textColor="#ff3333"
android:textSize="10dip" />
</LinearLayout>
<ImageView
android:id="#+id/imageView4"
android:layout_width="20dp"
android:layout_height="20dp"
android:padding="0dp"
android:src="#drawable/DropDownArrowIcon"
android:layout_alignParentRight="true" />
</RelativeLayout>
<LinearLayout
android:id="#+id/listViewborder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#2AACFF"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="0.5dp">
<ListView
android:layout_margin="1dp"
android:id="#+id/listView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#57585B"
android:divider="#drawable/list_divider"
android:dividerHeight="1dp" />
</LinearLayout>
<TextView
android:text="Type of bussinness"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/bankInvesttxt"
android:textSize="15dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:id="#+id/layoutView"
android:background="#drawable/customborder">
<LinearLayout
android:layout_centerVertical="true"
android:id="#+id/bankInvestTextlayout"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dip">
<TextView
android:id="#+id/bankInvestviewtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-Select-"
android:textColor="#FFFFFF"
android:textSize="10dip" />
</LinearLayout>
<ImageView
android:id="#+id/bankInvestimageView"
android:layout_width="20dp"
android:layout_height="20dp"
android:padding="0dp"
android:src="#drawable/DropDownArrowIcon"
android:layout_alignParentRight="true" />
</RelativeLayout>
<LinearLayout
android:id="#+id/bankInvestlistViewborder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#2AACFF"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="0.5dp">
<ListView
android:layout_margin="1dp"
android:id="#+id/bankInvestlistView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#57585B"
android:divider="#drawable/list_divider"
android:dividerHeight="1dp" />
</LinearLayout>
</ScrollView>
Try this: layoutView onClick set visiblity as visible the listView and listview itemselected set visiblity as gone. (Do this for both dropdown)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/layoutView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp" >
<LinearLayout
android:id="#+id/Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"
android:paddingLeft="10dip" >
<TextView
android:id="#+id/viewtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-Select-"
android:textColor="#ff3333"
android:textSize="10dip" />
</LinearLayout>
<ImageView
android:id="#+id/imageView4"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:padding="0dp" />
</RelativeLayout>
<LinearLayout
android:id="#+id/listViewborder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#2AACFF"
android:gravity="center_horizontal"
android:orientation="vertical"
android:layout_below="#+id/layoutView"
android:visibility="gone"
android:padding="0.5dp" >
<ListView
android:id="#+id/listView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:cacheColorHint="#57585B"
android:dividerHeight="1dp" />
</LinearLayout>
<TextView
android:id="#+id/bankInvesttxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:text="Type of bussinness"
android:layout_below="#+id/layoutView"
android:textSize="15dp" />
<RelativeLayout
android:id="#+id/rel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bankInvesttxt"
android:padding="8dp" >
<LinearLayout
android:id="#+id/bankInvestTextlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"
android:paddingLeft="10dip" >
<TextView
android:id="#+id/bankInvestviewtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="-Select-"
android:textColor="#FFFFFF"
android:textSize="10dip" />
</LinearLayout>
<ImageView
android:id="#+id/bankInvestimageView"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:padding="0dp" />
</RelativeLayout>
<LinearLayout
android:id="#+id/bankInvestlistViewborder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#2AACFF"
android:gravity="center_horizontal"
android:orientation="vertical"
android:visibility="gone"
android:layout_below="#+id/rel"
android:padding="0.5dp" >
<ListView
android:id="#+id/bankInvestlistView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:cacheColorHint="#57585B"
android:dividerHeight="1dp" />
</LinearLayout>
</RelativeLayout>
I have a parent scrollview and a listview Inside it. The parent scrollview's property affects the child listview's scrolling property. I can't scroll the listview Only scrollview's other child views are scrolling. How can I solve this issue.
I used the following xml:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/newmenu_layout"
android:layout_marginBottom="120dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:overScrollMode="never"
android:scrollbars="none" >
<LinearLayout
android:id="#+id/edit_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/ImageList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:scrollbars="none" >
</ListView>
<RelativeLayout
android:id="#+id/videodetail"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:background="#drawable/edt_stroke_bg"
android:orientation="horizontal" >
<ImageView
android:id="#+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="#drawable/video_notes" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/img"
android:text="#string/videoattach" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/audiodetail"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:background="#drawable/edt_stroke_bg"
android:orientation="horizontal"
android:visibility="gone" >
<ImageView
android:id="#+id/imgaudio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="#drawable/audio_notes" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/imgaudio"
android:text="Audio attachment" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/drawingdetail"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_marginTop="5dp"
android:background="#drawable/edt_stroke_bg"
android:orientation="horizontal"
android:visibility="gone" >
<ImageView
android:id="#+id/drawing_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="#drawable/video_notes" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toRightOf="#+id/drawing_img"
android:text="Drawing attachment" />
</RelativeLayout>
<LinearLayout
android:id="#+id/edt_check"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_marginTop="5dp"
android:background="#drawable/edt_stroke_bg"
android:orientation="vertical"
android:paddingStart="5dp" >
<EditText
android:id="#+id/body"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/transparent"
android:gravity="top"
android:imeOptions="actionDone"
android:paddingLeft="10dp"
android:paddingRight="5dp"
android:paddingTop="5dp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
Is there is any properties for listview or any listeners to fix the issue? Thanks in advance.
Your design is incorrect. You should never put a ListView inside a ScrollView. ListView implements it own scrolling , and it won't receive any gesture as they are handled by the ScrollView. It won't work.
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
I am developing an Android Application and I have an Activity that looks like this. I have a header and a footer that have fixed positions, and a ListView with clickable items in the middle. Below the ListView, I have a button.
It is working when I have a few items, but as I add more items, the button begins to disappear, like this.
When I have more items in that list that can be shown in the page, I have a scroll in the list. If I scroll down like this I can see all the items in the list, but the button is hidden.
I have had a lot of problems before trying to add a ListView inside a ScrollView, so I know it doesn't work. As I am new in Android development, perhaps my XML layout files are a bit confusing, but I have a parent LinearLayout with two RelativeLayouts inside, one for the header and one for the middle and footer. The XML is something like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFFFFF">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/background"
android:gravity="center_vertical">
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="#string/baseTitle"
android:textColor="#FFFFFF"
android:layout_centerVertical="true"
android:textSize="18dp"
android:textStyle="bold"/>
<Button
android:id="#+id/buttonHelp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="#drawable/button_help"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="fill_vertical">
<LinearLayout
android:id="#+id/buttonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center"
android:background="#bdbdbd"
android:layout_alignParentBottom="true">
<RelativeLayout
android:id="#+id/bottomButtomBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:orientation="horizontal">
<Button
android:id="#+id/myGroups"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="#string/myGroups"
android:gravity="center"
android:textSize="13dp"
android:textColor="#000000"
android:background="#layout/button_meus_grupos"/>
<Button
android:id="#+id/createGroups"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_centerInParent="true"
android:text="#string/createGroups"
android:gravity="center"
android:textSize="13dp"
android:textColor="#000000"
android:background="#layout/button_criar_grupos"/>
<Button
android:id="#+id/configurations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:text="#string/configurations"
android:gravity="center"
android:textSize="13dp"
android:textColor="#000000"
android:background="#layout/button_configuracoes"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_above="#id/buttonBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/listContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical"
>
<RelativeLayout
android:id="#+id/searchBarLayout"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:orientation="horizontal"
android:background="#ffffff"
android:gravity="center_vertical"
android:clickable="true"
>
<TextView
android:id="#+id/myGroupsLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/myGroups"
android:layout_centerInParent="true"
android:textColor="#bdbdbd"
android:textSize="16dp"
android:textStyle="bold"
/>
<ImageView
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/ic_search" />
</RelativeLayout>
<View android:layout_height="2dip"
android:layout_width="wrap_content"
android:background="#cccccc"
/>
<ListView android:id="#+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:cacheColorHint="#000000"
/>
<Button
android:id="#+id/buttonCreateGroup"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:background="#layout/button_confirm"
android:layout_gravity="center_horizontal"
android:text="#string/createOneGroup"
android:textColor="#FFFFFF"
android:textSize="22dp"
android:layout_marginTop="15dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
Does anyone have any tips on how can I keep the footer fixed, scroll down until the end of the list and then show the button? I want that it looks like the button is the last item at the List.
EDIT: Entire XML posted
The ListView and the Button should be in a RelativeLayout and in the Button you should set android:layout_below="#id/listview"
<RelativeLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="#+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#000000"
android:textColor="#000000" />
<Button
android:layout_below="#id/listview"
android:id="#+id/buttonCreateGroup"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:layout_marginTop="15dp"
android:background="#layout/button_confirm"
android:text="#string/createOneGroup"
android:textColor="#FFFFFF"
android:textSize="22dp" />
</RelativeLayout>
Try it in the following manner:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout //Header
android:layout_alignParentTop="true">
</RelativeLayout>
<ListView
android:layout_below="#+id/header" />
<RelativeLayout //Button(footer)
android:layout_alignParentBottom="true"
android:layout_below="#+id/listView" >
</RelativeLayout>
</RelativeLayout>
The only way I could achieve the exact requirements I explained above was doing the following:
-In the XML file with the layout of the list items, I added a button with android:visibility="gone".
-In my custom ListView adapter, I always add an empty object in the last position. I simply add an object with a flag that shows it is the last in the list.
-In the method getView() that I override in the custom Adapter, I check if the object in the current position has the flag indicating that it is the last in the list. If so, I set the button visibility to VISIBLE, otherwise I fill the other components.
If anyone is facing the same problem and needs some sample code from my solution just ask here.
Try this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:text="baseTitle"
android:textColor="#FFFFFF"
android:textSize="18dp"
android:textStyle="bold" />
<Button
android:id="#+id/buttonHelp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="fill_vertical"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/buttonBar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/bottomButtomBar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:orientation="horizontal" >
<Button
android:id="#+id/myGroups"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:gravity="center"
android:text="myGroups"
android:textColor="#000000"
android:textSize="13dp" />
<Button
android:id="#+id/createGroups"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:gravity="center"
android:text="createGroups"
android:textColor="#000000"
android:textSize="13dp" />
<Button
android:id="#+id/configurations"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:gravity="center"
android:text="configurations"
android:textColor="#000000"
android:textSize="13dp" >
</Button>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#id/buttonBar"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/listContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
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" >
<RelativeLayout
android:id="#+id/searchBarLayout"
android:layout_width="fill_parent"
android:layout_height="48dp"
android:clickable="true"
android:gravity="center_vertical"
android:orientation="horizontal" >
<TextView
android:id="#+id/myGroupsLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="myGroups"
android:textColor="#bdbdbd"
android:textSize="16dp"
android:textStyle="bold" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp" >
</ImageView>
</RelativeLayout>
<ScrollView
android:id="#+id/scroll"
android:layout_width="fill_parent"
android:layout_height="280dip"
android:layout_margin="7dip"
android:scrollbars="none" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ListView
android:id="#+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#000000"
android:textColor="#000000" />
<Button
android:id="#+id/buttonCreateGroup"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="20dp"
android:layout_marginTop="15dp"
android:text="createOneGroup"
android:textColor="#FFFFFF"
android:textSize="22dp" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>