How to align textviews when listviews are null? - android

So here is my problem:
I have here an edittext, 2 textviews and 2 listviews. The functionality of this activity is a search activity. when you type a certain word or phrase, there can be a result in either in Tools or Articles. My main problem is, when both tools and articles cannot find that word, I want the one in the red box, be something like this:
but I don't know how. I tried hiding the listviews but still I failed. So can you help me with this matter? Here is the xml file:
<?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="fill_parent"
android:background="#color/white"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/navbar_search"
android:paddingLeft="5dp" >
<ImageView
android:id="#+id/buttonBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="#drawable/btn_back" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/violet"
android:padding="5dp" >
<EditText
android:id="#+id/editTextSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/hint_search"
android:paddingLeft="35dp" >
</EditText>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editTextSearch"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:src="#drawable/search" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#color/blue"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >
<TextView
android:id="#+id/textArticlesResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/label_articles"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:textStyle="bold" />
<ListView
android:id="#+id/listViewArticlesResult"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/textArticlesResult"
android:cacheColorHint="#color/white"
android:scrollbars="none"
android:visibility="gone" >
</ListView>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#color/blue"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >
<TextView
android:id="#+id/textToolsResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="#string/label_tools"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:textStyle="bold" />
<ListView
android:id="#+id/listViewToolsResult"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/textToolsResult"
android:cacheColorHint="#color/white"
android:scrollbars="none" >
</ListView>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="46dp" >
<ImageView
android:id="#+id/tabHome"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:scaleType="fitXY"
android:src="#drawable/tab_home_unselected" />
<ImageView
android:id="#+id/tabFb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:scaleType="fitXY"
android:src="#drawable/tab_fb_unselected" />
<ImageView
android:id="#+id/tabSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:scaleType="fitXY"
android:src="#drawable/tab_search_selected" />
<ImageView
android:id="#+id/tabFaves"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:scaleType="fitXY"
android:src="#drawable/tab_myfaves_unselected" />
<ImageView
android:id="#+id/tabSettings"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:scaleType="fitXY"
android:src="#drawable/tab_settings_unselected" />
</LinearLayout>
</LinearLayout>

What I've done is to programatically hide the view. In my case, I wanted to hide the TextView when the content provider returned an empty string. Do this by:
TextView address = (TextView) findViewById(R.id.address);
address.setVisibility(View.GONE);
Don't forget to re-enable the TextView when you get a non-empty string by:
address.setVisibility(View.VISIBLE);
Note that View.INVISIBLE will only make the TextView disappear. View.GONE makes it so the TextView isn't even accounted for in the layout.

Related

how to make listview to take its appropriate lenght without scroll

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>

how to partition Activity in 3 parts for different Controls

<?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:orientation="vertical" >
<RelativeLayout
android:id="#+id/contact_relMainHeader"
android:layout_width="match_parent"
android:layout_height="50dip"
android:background="#16A180"
android:padding="5dp" >
<ImageView
android:id="#+id/contact_btnMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:src="#drawable/scrol" />
<ImageView
android:id="#+id/contact_btnLogout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:src="#drawable/lock" />
<ImageView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:src="#drawable/centertext" />
</RelativeLayout>
</RelativeLayout>
This is My Screen currently looking Like this .http://snag.gy/kwjAn.jpg i have to make of layout 3 partition vertically first for Google map ,Second for Name Display and , Third one for chat window actually i have make lay Out like this 10 part divide in to 4:2:4 3segement http://snag.gy/exrsu.jpg like this Layout. please help am unable to do this .
Try this ......
<?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:orientation="vertical" >
<RelativeLayout
android:id="#+id/contact_relMainHeader"
android:layout_width="match_parent"
android:layout_height="50dip"
android:background="#16A180"
android:padding="5dp" >
<ImageView
android:id="#+id/contact_btnMenu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/contact_btnLogout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginBottom="5dip"
android:layout_marginTop="5dip"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:gravity="center"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
<LinearLayout
android:layout_below="#+id/contact_relMainHeader"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_weight="40"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:background="#ff0000"
android:orientation="vertical"
>
</LinearLayout>
<LinearLayout
android:layout_weight="20"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:background="#000000"
>
</LinearLayout>
<LinearLayout
android:layout_weight="40"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:orientation="vertical"
android:background="#ffff00"
>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Fragments will help you get the desired result. I can explain to you the logic without writing the code(...you need to put that effort). Your layout should have 3 fragments
The mapfagment can be at the top. Mapfragments
This can be followed by the fragment that contains a textview.
And the last one will contain your chat window.

android:layout_alignParentRight="true" does nothing

I have an ImageView which I've set to android:layout_alignParentRight="true" however it does not appear on the right side of the screen and I'm not sure why (it is the white square appearing centered horizontally in the screenshot below).
I understand this can only be used with a RelativeLayout - but I've used one - so I'm not sure exactly why this is happening.
<?xml version="1.0" encoding="utf-8"?>
<com.example.project.DragLayer xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:launcher="http://schemas.android.com/apk/res/com.android.launcher"
android:id="#+id/drag_layer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/black" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1.0" >
<GridView
android:id="#+id/image_grid_view"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.8"
android:background="#color/grid_background"
android:gravity="center"
android:horizontalSpacing="2dip"
android:numColumns="#integer/num_columns"
android:stretchMode="columnWidth"
android:verticalSpacing="2dip" />
<RelativeLayout
android:id="#+id/bottom_part"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_centerHorizontal="true"
android:layout_weight="0.2"
android:background="#android:color/black"
android:orientation="horizontal"
android:weightSum="1.0" >
<Button
android:id="#+id/button_add_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:onClick="onClickAddImage"
android:text="Add image" />
<com.example.project.DeleteZone
android:id="#+id/delete_zone_view"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/delete_zone" />
<FrameLayout
android:id="#+id/image_source_frame"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_weight="0.5" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginRight="5dp"
android:layout_weight="1" >
<ImageView
android:id="#+id/sqwhite"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginRight="5dp"
android:layout_weight="1" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/sqwhite"
android:layout_marginRight="5dp" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/editText1"
android:layout_marginRight="5dp"
android:text=""
android:textColor="#android:color/white" />
</RelativeLayout>
</FrameLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</com.example.project.DragLayer>
The one glaring thing that jumps out at me is the redefinition of the xmlns, which any compiler doesn't like and may prevent proper generation of the layout. When I removed that and some of your dead code and tried running this, the "sqwhite" appeared on the right side. See if fixing these items helps:
Your first LinearLayout redefines the XML Namespace, which is an error. This could be what's preventing the XML from compiling properly.
Other minor items:
layout_weight only applies to children of LinearLayouts, so having them in other ViewGroups is unnecessary. Remove them from image_source_frame and its children
Having bottom_part use layout_centerHorizontal in a vertical LinearLayout is redundant and should also be removed.
Having layout_alignParentRight in your RelativeLayout is useless, since only children of RelativeLayouts can use it. Please remove.
Maybe I'm missing it from the code you provided, but where is the white square actually coming from? You didn't set an android:src attribute to the ImageView. So is it possible that the actual sqwhite is in the right place, and that that white square represents something else?
EDIT: I've re-pasted your code here, with the items I listed removed. Maybe this will help:
<?xml version="1.0" encoding="utf-8"?>
<com.example.project.DragLayer xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drag_layer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/black" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1.0" >
<GridView
android:id="#+id/image_grid_view"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_weight="0.8"
android:background="#color/grid_background"
android:gravity="center"
android:horizontalSpacing="2dip"
android:numColumns="#integer/num_columns"
android:stretchMode="columnWidth"
android:verticalSpacing="2dip" />
<RelativeLayout
android:id="#+id/bottom_part"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_weight="0.2"
android:background="#android:color/black"
android:weightSum="1.0" >
<Button
android:id="#+id/button_add_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:onClick="onClickAddImage"
android:text="Add image" />
<com.example.project.DeleteZone
android:id="#+id/delete_zone_view"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="#drawable/delete_zone" />
<FrameLayout
android:id="#+id/image_source_frame"
android:layout_width="fill_parent"
android:layout_height="80dp" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:layout_marginRight="5dp" >
<ImageView
android:id="#+id/sqwhite"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:layout_marginRight="5dp"
android:src="#android:drawable/ic_delete" /> <!-- for testing -->
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/sqwhite"
android:layout_marginRight="5dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#id/editText1"
android:layout_marginRight="5dp"
android:text=""
android:textColor="#android:color/white" />
</RelativeLayout>
</FrameLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>
</com.example.project.DragLayer>

How to display 2 No Results Found text when search result is not found? In Android

I have 2 TextViews and 2 ListViews and an EditText in my main xml file.
The "Search" EditText is first,
then "Tools" TextView,
then "Tools" ListView,
then "Articles" TextView,
then "Articles" ListView.
What I wanted to do is display "No Results Found for Tools" when someone type in a word (i.e "test") and it does not exists in my sql, I want to display this in my tools section and "No Results found for Articles" in my articles section
My main problem is, when I run the project, it has a huge space between the textViews.
It looks like this
No Results Found in Tools
No Results Found in Articles.
The output that I want to achieve is:
No Results Found in Tools
No Results Found in Articles
I tried setting the visibility of the listview to gone but still doesn't work. Can you help me?
EDIT: here is my xml layout for this
<?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="fill_parent"
android:background="#color/white"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/navbar_search"
android:paddingLeft="5dp" >
<ImageView
android:id="#+id/buttonBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="#drawable/btn_back" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/violet"
android:padding="5dp" >
<EditText
android:id="#+id/editTextSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/hint_search"
android:paddingLeft="35dp" >
</EditText>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editTextSearch"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:src="#drawable/search" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#color/blue"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >
<TextView
android:id="#+id/textArticlesResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="#string/label_articles"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:textStyle="bold" />
<ListView
android:id="#+id/listViewArticlesResult"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/textArticlesResult"
android:cacheColorHint="#color/white"
android:fadeScrollbars="false" >
</ListView>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#color/blue"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >
<TextView
android:id="#+id/textToolsResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="#string/label_tools"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:textStyle="bold"
android:layout_below = "#id/listViewArticlesResult" />
<ListView
android:id="#+id/listViewToolsResult"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/textToolsResult"
android:cacheColorHint="#color/white"
android:fadeScrollbars="false" >
</ListView>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="46dp" >
<ImageView
android:id="#+id/tabHome"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:scaleType="fitXY"
android:src="#drawable/tab_home_unselected" />
<ImageView
android:id="#+id/tabFb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:scaleType="fitXY"
android:src="#drawable/tab_fb_unselected" />
<ImageView
android:id="#+id/tabSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:scaleType="fitXY"
android:src="#drawable/tab_search_selected" />
<ImageView
android:id="#+id/tabFaves"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:scaleType="fitXY"
android:src="#drawable/tab_myfaves_unselected" />
<ImageView
android:id="#+id/tabSettings"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="#string/desc"
android:scaleType="fitXY"
android:src="#drawable/tab_settings_unselected" />
</LinearLayout>
</LinearLayout>
Chunck of Your code:`
<TextView
android:id="#+id/textArticlesResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="#string/label_articles"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:textStyle="bold" />
<ListView
android:id="#+id/listViewArticlesResult"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/textArticlesResult"
android:cacheColorHint="#color/white"
android:fadeScrollbars="false" >
</ListView>
</RelativeLayout>`
replace to:
<TextView
android:id="#+id/textArticlesResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:text="#string/label_articles"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#color/black"
android:textStyle="bold" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#color/blue"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp"
android:visibility="visible" >
<ListView
android:id="#+id/listViewArticlesResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#color/white"
android:fadeScrollbars="false"
android:visibility="visible" >
</ListView>
</RelativeLayout>
and modify android:visibility of RelativeLayout which encapsulates your ListView

ListView with button at the bottom in Activity with fixed header and footer

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>

Categories

Resources