Android layout not display after listview if more item in list view.if i add 4 to 5 item my button is out of screen. and if i use 'android:layout_alignParentBottom="true"' then my linear layout is on last listview item.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/sereen_2_bg" >
<ListView
android:id="#+id/cartList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:footerDividersEnabled="false"
>
</ListView>
<LinearLayout
android:id="#+id/linearCartFooter"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:gravity="right"
android:orientation="vertical"
android:layout_below="#id/cartList"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/total"
android:textColor="#color/white" />
<TextView
android:id="#+id/txtCartTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="#color/white"
android:padding="3dp"
android:text="#string/total"
android:textColor="#color/black" />
</LinearLayout>
<Button
android:id="#+id/btnCartCheckout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="#drawable/sereen4_submit" />
</LinearLayout>
</RelativeLayout>
I was able to solve this issue by adding alignParentBottom="true" to bottom layout and applying a bottom margin to list view like
android:layout_marginBottom="75dp"
so that it does not overlap with my bottom layout.
Add 'android:layout_alignParentTop="true"' to your ListView and possibly android:layout_below="#id/cartList" to your Button if you want the ListView to be on top of the Layout and the bottom Views also visible all the time.
Related
I have used GridView in my project and with that I included the ViewHolder.
Now, the customer wants to show the data using an ExpandableListView for the fact that he wants to only show the header and when the user clicks on the header, it shows the child below it.
Having no prior experience, I want to know if it possible to change from GridView to ExpandableListView easily in the code.
Note that I have also included text search on the Grid. Will that still be available if I switch to ExpandableListView?
If the above is possible, can anyone help how I could achieve it.
The Grid row xml is as follows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="8dip"
android:paddingRight="4dip">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.8">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:typeface="sans"
android:textSize="13sp"
android:textStyle="bold"
android:id="#+id/placeName"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#88FFFFFF"
android:typeface="sans"
android:textSize="13sp"
android:textStyle="bold"
android:id="#+id/theme"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:id="#+id/Title"/>
<TextView
android:id="#+id/Details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1dip"
/>
<TextView
android:id="#+id/scheduleDays"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_gravity="bottom"
android:layout_marginRight="5dip"
android:layout_marginTop="7dip"
android:text="Family, Friends, Relatives, Grand-Parents"
android:textStyle="bold"/>
<TextView
android:id="#+id/Date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="bottom"
android:layout_gravity="right"
android:layout_marginRight="5dip"
/>
</LinearLayout>
<LinearLayout
android:id="#+id/rightLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:orientation="vertical"
android:minWidth="60dp"
android:layout_weight="0.2">
<ImageView
android:id="#+id/starButton"
android:layout_width="40dp"
android:layout_gravity="right"
android:layout_marginRight="5dip"
android:layout_height="40dp"
android:background="#00FFFFFF"
android:src="#drawable/Favourite"/>
<ImageView
android:id="#+id/showMeButton"
android:layout_width="40dp"
android:layout_gravity="right"
android:layout_marginRight="15dip"
android:src="#drawable/showMe"/>
</LinearLayout>
</LinearLayout>
<View
android:id="#+id/separator"
android:layout_marginTop="5dip"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#33000000" />
</LinearLayout>
With ListView, I want to show PlaceName, Favourite Button and ShowMe Button as the headers and the rest as the child.
You can integrate the Expandable ListView in an Layout, like LinearLayout.
For this Change the Layout type in the layout.xml of your activity
To send the Data to the ListView you need to use an BaseExpandableListAdapter that pulls the Content out of an Array or a Database.
Example for the layout.xml
<LinearLayout .... >
<ExpandableListView
.... >
</ExpandableListView>
</LinearLayout>
can you show your xml file. well can be achieve is many ways.
like change your layout container from grid layout to linear layout
as in your adapter
and set your View in onCreate
recycler.setHasFixedSize(true);
final LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
recycler.setLayoutManager(layoutManager);
adapter = new Adapter(getActivity());
recycler.setAdapter(adapter);
I am trying to layout an actionbar spinner dropdown list. I have a textview and an imageview in each row. I want the textview to align to the far left of the dropdown (with the paddingLeft) and I want the imageview to align to the far right of the dropdown. The text in the textviews varies in length, so the icons end up being aligned to the immediate right of the textviews. This layout provides a two line item on the actionbar with the spinner title and selected item name.
Here is my current layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/spinner_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp" />
<LinearLayout
android:id="#+id/item_row"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="-5dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:layout_weight="1"
android:gravity="left"
android:textSize="18sp" />
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:contentDescription="icon" />
</LinearLayout>
</LinearLayout>
I've tried a relative layout like below, with similar results (see screen shot). The bluetooth icon is a stand in for the yet to be created icon (same size):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/spinner_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp" />
<RelativeLayout
android:id="#+id/item_row"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:id="#+id/item_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textSize="18sp" />
<ImageView
android:id="#+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/item_name"
android:contentDescription="icon" />
</RelativeLayout>
Use a RelativeLayout instead of a LinearLayout, and use the alignParentLeft/Right attributes on your children to place them correctly.
I am trying to add elements to my scrollview,
this scroll view has a vertical linear layout inside of it.
(i added another linear layout - horizontl, inside that will manage 2 textviews and an image according to the attributes i assigned them),
i am trying to add elements of this inner layout to my scroll view (id=insideLineLayout)
(each element added to scrollview will contain these 2 texts and an image)
because of the fact scrollview can only have 1 child i am unable to do this.
would appreciate some help, nothing seems to be working here.
Thanks.
my current xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/searchScreenOuterLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="#+id/catagoryselectedText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="70dp"
android:text="selected catagory"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="12dp"
android:orientation="horizontal" >
<EditText
android:id="#+id/searchText"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp" />
<ImageButton
android:id="#+id/searchButton"
android:layout_width="50dp"
android:layout_height="40dp"
android:background="#drawable/search_icon" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="10dp"
android:orientation="horizontal" >
<TextView
android:id="#+id/radiusText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:paddingTop="5dp"
android:text="Search Radius"
android:textAppearance="?android:attr/textAppearanceMedium" />
<SeekBar
android:id="#+id/radiusBar"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp" />
</LinearLayout>
<ScrollView
android:id="#+id/searchScrollView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/searchScrollViewLinear"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="10dp" >
<LinearLayout
android:id="#+id/insideLineLayout"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:orientation="horizontal"
android:weightSum="100"
>
<TextView
android:id="#+id/linesPrice"
android:layout_weight="20"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text="tmp1"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/linesInfo"
android:layout_weight="60"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:text="tmp2"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="#+id/imageInfo"
android:layout_width="40dp"
android:layout_height="match_parent"
android:background="#drawable/tv_icon" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Consider how long your list can get as ListView has been optimized in many ways which a regular scroll view is not. If you have too many elements you might start get out of memory exceptions.
In order to dynamically add views to a ScrollView you first need to get the container view inside the ScrollView (most likely a LinearLayout), then you simply do following for each view you add:
View view = inflater.inflate(R.layout.view_to_add, container, false); // this is used if you create from xml, if you make it in code you'd use the regular constructor.
// update the view content (view.findViewById(); etc.)
container.addView(view);
had make layout for showing the content in listview and a button below on list view for displaying more information on list view ,so first i am showing only 4 rows in list view and when i next time click on button 4 rows again added in list so now my button goes down in screen so how to make whole layout scroll able so that i can go to button via scrolling my layout is..
listplacehold.xml is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#1A77BD"
>
<ListView
android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:drawSelectorOnTop="false" />
<View
android:id="#+id/horizontolline"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_below="#id/android:list"
android:background="#000000"
/>
<Button
android:text="Load More..."
android:textColor="#color/white"
android:id="#+id/keywordsearchbutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/horizontolline"
android:drawableLeft="#drawable/load_more_off"
android:gravity="left|center_vertical"
android:background="#1A77BD"
/>
</RelativeLayout>
and for list item layout is: listitem.xml is
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="#+id/img"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<!-- Location where barrio items will be displayed -->
<TextView
android:id="#+id/reportid"
android:layout_marginLeft="70dip"
android:text="reporet id"
android:textColor="#color/white"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
<TextView android:id="#+id/status"
android:textColor="#color/white"
android:text="status"
android:layout_marginTop="40dip"
android:layout_marginLeft="200dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:id="#+id/title"
android:text="title"
android:layout_marginLeft="150dip"
android:textColor="#color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/date"
android:text="dateeeeeee"
android:layout_marginLeft="70dip"
android:layout_marginTop="40dip"
android:textColor="#color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
items are dynamically loadein list view when button click
i think that scroll will be set on above xml means on "listplacehold.xml" but how?,when i am doing it is set to for half screen,means it is not displaying in whole view... Thanks for help in advance.
don't use the ScrollView with the combination of the ListView. Instead make your layout like this.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#1A77BD" >
<Button
android:id="#+id/lodmore"
android:text="Load More..."
android:textColor="#color/white"
android:id="#+id/keywordsearchbutton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true""
android:drawableLeft="#drawable/load_more_off"
android:gravity="left|center_vertical"
android:background="#1A77BD"/>
<View
android:id="#+id/horizontolline"
android:layout_width="fill_parent"
android:layout_height="1dip"
android:layout_above="#id/loadmore"
android:background="#000000"/>
<ListView
android:id="#+id/android:list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_alignParentTop="true"
android:layout_above="#id/horizontolline/>
</RelativeLayout>
put scrollview over your root layout and remember only one layout node is allowed under scrollview.....
refer this doc:
http://developer.android.com/reference/android/widget/ScrollView.html
I have a ListView in a dialog and I need to show a button after the list.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content">
<TextView android:id="#+id/tvwGameOver" android:layout_weight="1" android:gravity="center"
android:textSize="25sp" android:visibility="gone"
android:layout_width="fill_parent" android:layout_height="wrap_content"/>
<LinearLayout
android:id="#+id/lloPlayerNames" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:footerDividersEnabled="true"
android:headerDividersEnabled="true" android:layout_below="#id/tvwGameOver">
<TextView
android:id="#+id/tvwGameNumberHeader" android:layout_weight="1" android:gravity="right"
android:text="#string/scores_GameNumber" android:textSize="12sp"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginRight="13sp"/>
<TextView
android:id="#+id/tvwPlayer0Name" android:layout_weight="1" android:gravity="right"
android:textSize="12sp"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginRight="13sp"/>
<TextView
android:id="#+id/tvwPlayer1Name" android:layout_weight="1" android:gravity="right"
android:textSize="12sp"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginRight="13sp"/>
<TextView
android:id="#+id/tvwPlayer2Name" android:layout_weight="1" android:gravity="right"
android:textSize="12sp"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginRight="13sp"/>
<TextView
android:id="#+id/tvwPlayer3Name" android:layout_weight="1" android:gravity="right"
android:textSize="12sp"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:layout_marginRight="13sp"/>
</LinearLayout>
<ListView
android:id="#+id/lvwScores" android:layout_below="#id/lloPlayerNames"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:divider="#FFFFFF" android:dividerHeight="1dip"
android:layout_weight="1"
android:footerDividersEnabled="true" android:headerDividersEnabled ="true"/>
<Button android:id="#+id/btnOK"
android:layout_height="wrap_content" android:layout_width="120dip"
android:layout_weight="1"
android:text="OK" android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
Problem is that when the list gets to be too big it just passes the button and the button sits over the top of the list.
I tried to add android:layout_below="#id/lvwScores" to the button but then, when the list is empty, I get a button that runs from the bottom of the screen to the bottom of the list.
If I remove the android:layout_alignParentBottom="true" then the dialog is made small.
At the end of the day, I am looking to have the list filling most of the screen even if part of it is still empty (it is a scores screen), with the button at the bottom.
Any ideas?
This is what it looks like when empty:
It is great, except that when the list builds up and reaches the bottom is down not stop at the button.
Can you maybe give the list view or the list view's container a margin at the bottom that is the height of the button? Just as a test, give the button a height of 30 dips and have the listview or listview's container have a bottom margin of 30 dips to see if it still runs over behind the button.
The button should have
android:layout_below="#id/lvwScores"
alignParentBottom isn't the best approach for RelativeLayouts that do not fill_parent.