My app has two sections, stuff to do for today, and for upcoming days.
I am able to hide/show these by pressing on the corresponding button but when I open both, there can be too much info and I can only scroll the listview for the upcoming days and not the entire screen.
I did some searching and I kept seeing ScrollView pop up but I can't get that to work, it crashes my app.
Here is my XML file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="eu.agp_it.agpmobilemover.OverviewActivity">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1.0"
android:gravity="center"
android:id="#+id/layout_button_today">
<Button
android:id="#+id/overview_button_today"
android:layout_height="wrap_content"
android:layout_weight="0.95"
android:layout_width="0dp"
android:textSize="20sp"
android:text="#string/overview_today"
android:gravity="center"
android:layout_marginTop="5px"
android:layout_marginBottom="5px"
android:background="#drawable/custom_buttonoverview"
android:onClick="buttonTodayOnClick"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_listview_today"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layout_button_today">
<ListView
android:id="#+id/listviewtoday"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp"
android:visibility="visible"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_button_upcoming"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="1.0"
android:gravity="center"
android:layout_below="#id/layout_listview_today">
<Button
android:id="#+id/overview_button_upcoming"
android:layout_height="wrap_content"
android:layout_weight="0.95"
android:layout_width="0dip"
android:textSize="20sp"
android:text="#string/overview_upcoming"
android:background="#drawable/custom_buttonoverview"
android:gravity="center"
android:layout_marginTop="5px"
android:layout_marginBottom="5px"
android:onClick="buttonUpcomingOnClick"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_listview_upcoming"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/layout_button_upcoming">
<ListView
android:id="#+id/listviewupcoming"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp"
android:visibility="gone"/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
You probably don't need the ScrollView at all. The ListViews already do the scrolling for you. Nesting scrolling views isn't recommended.
Try taking out the ScrollView. Each LinearLayout could take up half the screen, or whatever amount you'd like. You could also use an ExpandableListView which would allow you to expand and collapse the assignments for today and upcoming days based on their header (Today, Upcoming). This way you would only need one ListView. So it would be easier to maintain.
Related
I am creating an Android app which has a main RelativeLayout and some LinearLayout within it.
Now i have this problem. When dragging items to the editor, e.g. a LinearLayout, it doesn't fit to the full width of the screen. How can I make this possible? This is my XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true"
android:gravity="fill"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<LinearLayout
android:id="#+id/itemDetailLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:fillViewport="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="#+id/itemImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="40dp"
android:minWidth="40dp"
android:src="#drawable/ic_launcher" />
<TextView
android:id="#+id/itemName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="Name"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:fillViewport="true" >
<TextView
android:id="#+id/itemRecentHigh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recent High" />
<TextView
android:id="#+id/itemRecentLow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recent Low" />
<TextView
android:id="#+id/itemAverage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Average" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/listViewLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/itemDetailLayout"
android:layout_marginTop="10dp"
android:fillViewport="true"
android:gravity="fill_horizontal"
android:orientation="vertical" >
<ListView
android:id="#+id/searchListView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
</ListView>
</LinearLayout>
Added a screenshot for more info. Added blue background to have some contrast.
Replace this:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
With
android:layout_width="match_parent"
android:layout_height="wrap_content"
into your LinearLayout or Remove all the Padding from main RelativeLayout
Removing padding makes the linear layout fit the entire screen of the device
The space between the blue part and the "end of the screen". On the sides and above the part where the back button and home button are.
Remove the padding from the root RelativeLayout.
Try
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical>
// Other views within the linear layout
</LinearLayout>
I suppose you are using Eclipse. Personally, I hate the Graphical Editor of Eclipse and I usually write the XML code directly because working with the editor is a real pain
Don't use fill_parent as it is deprecated.
Instead to your RelativeLayout set
android:layout_width="fill_parent"
android:layout_height="fill_parent"
Then, to the list view that you want to fill the rest of the screen, you can set this tags
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
By doing so, you are telling the XML that you want your ListView to do what fill_parent used to do in previous versions of Android.
Kind regards!
you should try something like the following :
<LinearLayout
android:id="#+id/itemDetailLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
...
</LinearLayout>
what i mean you should do this :
android:layout_width="fill_parent"
for every LinearLayout that you want its width to fill_parent .
FILL_PARENT means that the view wants to be as big as its parent as mentioned in the documentation .
and please give me some feedback
Hope That Helps .
I have a layout with listview and two buttons side by side at the bottom of the listview. Everything work fine until I have added the swiperefreshlayout for my listview.
My codes are as below.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFF"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/search_bar"
android:background="#color/colorPrimaryDark"
android:orientation="vertical"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
>
<EditText
android:id="#+id/keyword_editText"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:background="#drawable/search_edit_text"
android:hint="Keyword"
android:textColorHint="#color/list_item_title"
android:textColor="#000"
android:layout_centerVertical="true"
android:maxLines="1"/>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/listView_layout"
android:orientation="vertical"
android:layout_below="#+id/search_bar"
>
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/refresh"
android:layout_height="match_parent"
android:layout_width="match_parent">
<ListView
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"
android:id="#+id/RsListView"
android:dividerHeight="1dp"
android:divider="#D3D3D3"/>
</android.support.v4.widget.SwipeRefreshLayout>
<LinearLayout
android:id="#+id/test"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="#+id/req_history_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Request History"
android:layout_weight="1"
android:background="#drawable/request_history_button"
android:textColor="#drawable/button_text_color"
/>
<Button
android:id="#+id/apprv_history_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Approval History"
android:layout_weight="1"
android:background="#drawable/approval_history_button"
android:textColor="#drawable/button_text_color"
/>
</LinearLayout>
</LinearLayout>
Sorry for dumping my codes here as I can't figure out any other way for you guys to understand my code.
Please help
Inside LinearLayout usually all children have even dimension according to orientation. However, when you would like one child to take a little amount of place and another to fill the rest, you might be interested in layout_weight parameter. If the child that should fill the space gets android:layout_weight="1" it will fill the space making a place for other views.
In order to see the buttons add android:layout_weight="1" to SwipeRefreshLayout and set android:layout_height="0dp". That will make your buttons visible.
I think to do a overlay of layout, this is the code that I have now.:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white">
<ScrollView
android:id="#+id/content_scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/container_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/text_search"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:background="#color/white"
android:weightSum="2">
<EditText
android:id="#+id/input_search"
android:layout_width="0dp"
android:layout_height="match_parent"
android:hint="#string/placeholder_search"
android:layout_margin="5dp"
android:layout_weight="1.5"
android:inputType="text"
android:padding="5dp"
android:drawableRight="#drawable/ic_search"
android:background="#drawable/style_input"
android:imeOptions="actionSend"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.5"
android:src="#drawable/img_header" />
</LinearLayout>
<LinearLayout
android:id="#+id/list_search"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="-5dp"
android:layout_gravity="top"
android:orientation="vertical">
<TextView
android:id="#+id/no_result"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:visibility="gone"
android:text="#string/no_result"
android:gravity="center_horizontal|center_vertical|center"/>
<ListView
android:id="#+id/search_categorias"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></ListView>
</LinearLayout>
<LinearLayout
android:id="#+id/container_buttons_tall"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:background="#drawable/style_header">
<TextView
android:id="#+id/otherlayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="Other Layout" />
</LinearLayout>
<LinearLayout
android:id="#+id/container_buttons_tall1"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:background="#drawable/style_header"
android:weightSum="3">
<TextView
android:id="#+id/otherlayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="Other Layout 2" />
</LinearLayout>
<LinearLayout
android:id="#+id/container_buttons_tall2"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:background="#drawable/style_header"">
<TextView
android:id="#+id/otherlayoutn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"
android:text="Other Layout N" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
I want to overlay the next layouts after of the ID "#+id/text_search" with the rest, this list is the a search and show suggestions to users.
This list will overlay about others layouts that I define below, if the user want to make a search.
Are there some way easy of overlay? Or tutorial that can help me. I try to use RelativeLayout, but I didn't get to make it well.
Thanks in advance.
you can use the Relative Layout for this, but you need to specify the relations (thats why relative => relative to what)
means you have to set the postion of your +id/text_search relative to parent.
and also the elements which should do the overlayer have to be relative to parent.
todo so relative Layout uses layout properties like: below=(ID) toRightOf(ID) and so on.
you can start reading about it here:
http://developer.android.com/guide/topics/ui/layout/relative.html
but for the search you want todo, there is already a good advice howto it: so i recommend reading this article:
http://developer.android.com/guide/topics/search/search-dialog.html
and doing it right, like all the others apps do it, your customers will be satisfied then (don't need to learn something new )
I have a LinearLayhout that contains a listView and below it an ImageButton.
When I add items to the list, the imageButton is moving lower and lower, which is what I want but when there are many elements in the list so that is the list is big enough to fill the screen, I can scroll down to the bottom of the list, but no further, meaning I can't see the imageButton anymore.
Code:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/add_interest_layout_root"
android:orientation="vertical"
android:layout_width="match_parent"
android:background="#color/back"
android:layout_height="match_parent">
<ListView android:id="#android:id/list"
android:layout_width="match_parent"
android:divider="#drawable/downa"
android:footerDividersEnabled="false"
android:cacheColorHint="#android:color/transparent"
android:layout_gravity="center"
android:layout_marginTop="6dp"
android:layout_height="wrap_content">
</ListView>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/linearLayout2"
android:gravity="center">
<LinearLayout
android:orientation="vertical"
android:gravity="center_horizontal"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/LinearLayout16">
<ImageButton
android:src="#drawable/add"
android:id="#+id/btn_interest_more"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/transparent"></ImageButton>
<TextView
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_width="wrap_content"
android:id="#+id/TextView08"
android:text="be more\nspecific"
android:gravity="center"></TextView>
</LinearLayout>
</LinearLayout>
What am I doing wrong? I want to be able to see the ImageButton even when I scroll down.
You should do something like this. Mind you this is a pseudo code so you better fill the correct attributes.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/add_interest_layout_root"
android:layout_width="match_parent"
android:background="#color/back" android:layout_height="match_parent">
<LinearLayout android:layout_height="wrap_content"
android:layout_width="match_parent" android:id="#+id/linearLayout2"
android:gravity="center" android:layout_alignParentBottom="true">
<!-- LinearLayout elements same as above -->
</LinearLayout>
<ListView android:id="#android:id/list"
android:layout_above="#+id/linearLayout2"
android:layout_width="match_parent"
android:divider="#drawable/downa"
android:footerDividersEnabled="false"
android:cacheColorHint="#android:color/transparent"
android:layout_gravity="center"
android:layout_marginTop="6dp" android:layout_height="match_parent">
</ListView>
</RelativeLayout>
Here is exactly the solution to your problem: http://www.curious-creature.org/2010/08/15/scrollviews-handy-trick/ which is solved by setting fillviewport on your listview.
Add this to your LinearLayout that holds the ImageButton
android:layout_alignParentBottom="true"
UPDATE:
Forget the above code. I misunderstand you. Sorry.
Do this instead: Add this layout as your root layout
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scroll"
android:scrollbars="none"
android:layout_weight="1">
<!-- Your code -->
</ScrollView>
The button is hidden...why?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="15dp"
android:orientation="vertical">
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/feed_list"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="More"
android:id="#+id/feed_more"/>
</LinearLayout>
Assuming that the ListView has enough content to fill up the whole screen, it will since you told it to wrap_content. You can use weights to instruct the ListView to take up as much of the screen as is available, after the button has what it needs:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="15dp"
android:orientation="vertical">
<ListView
android:layout_width="fill_parent"
android:layout_height="0"
android:weight="1"
android:id="#+id/feed_list"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weight="0"
android:text="More"
android:id="#+id/feed_more"/>
you need to give weight 1 to the list view. then your button will be visible. try it.