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
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 layout where I have multiple components in a ScrollView. I want to include a List within the ScrollView. The problem is if I include a ListView within the scroll view, the ListView shows in a small space and the list scrolls too as the list adds items dynamically.
If I add the ListView out of the ScrollView It displays nicely but I dont want the list to scroll and be a part of the whole page
Here is my code:-
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/layoutMain"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10" >
<ScrollView
android:id="#+id/scrollNews"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="4" >
<!-- Main vertical LinearLayout -->
<LinearLayout
android:id="#+id/layoutList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/txtNewsTitle"
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:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#F8F8F8"
android:textSize="11sp" />
</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/txtNewsViews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="view"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FF3C6FA6" />
<ImageButton
android:id="#+id/btnComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:background="#color/white"
android:src="#drawable/btncommentpressed" />
<TextView
android:id="#+id/txtNewsComments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="view"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FF3C6FA6" />
</LinearLayout>
<ImageView
android:id="#+id/imgNewsImage"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/attini" />
<TextView
android:id="#+id/txtNewsBody"
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"
android:padding="10dp" >
<ImageView
android:id="#+id/btnComms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:background="#color/white"
android:src="#drawable/commspressed" />
<ImageButton
android:id="#+id/btnAddComms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/white"
android:src="#drawable/btnaddcommspressedxml"
android:textSize="10sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/getdata"
android:layout_gravity="bottom"
android:layout_weight="6"
android:divider="#b5b5b5"
android:dividerHeight="1dp"
android:listSelector="#drawable/list_selector"
android:padding="5dp"
android:transcriptMode="alwaysScroll"
android:visibility="invisible" />
</LinearLayout>
</LinearLayout>
There are hacks that enables ListView in a ScrollView but they are not good.
You should either have only one ListView with header and footer views. You should add these header and footers programatically.
Or you can have a ScrollView and a LinearLayout instead of ListView and you can add the items in the list one by one to the LinearLayout programatically.
If the list is the main thing and it is big then the first approach is better.
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.
This is the part of the Code of a very long Layout.So posting of whole code was of no use.
I want to align the RED circle.Both the positions are shown in the RED colored circles.
The ParentLayout of whole activity is a RelativeLayout but has nothing to do with this.
Please help me.I have tried all the things that I knew.
<LinearLayout
android:id="#+id/thumbnail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/texttitle"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#drawable/Layoutborder"
>
<LinearLayout
android:id="#+id/Linearimagetop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:layout_alignParentLeft="true"
android:background="#drawable/image_bg"
>
<ImageView
android:id="#+id/productimage1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/defaultimage"
android:layout_below="#+id/texttitle"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Availability "
android:textColor="#color/black"
android:textStyle="normal" />
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#color/black"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"/>
<TextView
android:id="#+id/availibility"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="In Stock"
android:textColor="#4A7023"
android:textStyle="normal"
android:layout_marginLeft="3dp"/>
</LinearLayout>
</LinearLayout>
Change the 3rd LinearLayout to :
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:padding="5dp" >
Not sure if you are satisfied with that kind of layout.
If this whole thing is inside a RelativeLayout, remove the outer LinearLayout (moving margins and such to the first child LinearLayout as required), and change the second child LinearLayout - the one with 5dp padding - to have
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
If you don't want to do this and have to keep the outer LinearLayout for some reason, move
android:layout_marginTop="20dp"
from the parent LinearLayout to the first child, and set layout_width of the second child to fill_parent, and add android:gravity="right" to it.
The code you provided does not show where you have specified the properties of RED text "here". You could probably just add it as another element in your relative layout where you specify the availability and stock which would align it with the preceding text.
Edit: (after understanding your actual problem)
I would suggest wrapping in another linear layout which will enable you to position the text above the picture as shown in the code below.
<?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="100dp"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="20dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Availability "
android:textStyle="normal" />
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp" />
<TextView
android:id="#+id/availibility"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="3dp"
android:text="In Stock"
android:textColor="#4A7023"
android:textStyle="normal" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:id="#+id/thumbnail"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/texttitle"
android:layout_marginBottom="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/Linearimagetop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:padding="3dip" >
<ImageView
android:id="#+id/productimage1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/texttitle"
android:src="#drawable/button" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
This was the Another way achieve the above Output.Hope it may help SomeOne.
<RelativeLayout
android:id="#+id/thumbnail"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/white"
>
<LinearLayout
android:id="#+id/Linearimagetop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dip"
android:background="#drawable/image_bg"
android:layout_alignParentLeft="true"
>
<ImageView
android:id="#+id/productimage1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/defaultimage"
android:layout_below="#+id/texttitle"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Availability "
android:textColor="#color/black"
android:textStyle="normal" />
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="#color/black"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
/>
<TextView
android:id="#+id/availibility"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="In Stock"
android:textColor="#4A7023"
android:textStyle="normal"
android:layout_marginLeft="3dp"
/>
</LinearLayout>
</RelativeLayout>