display the imageview after listview - android

i want to add the imageview after listview. In listview i have so many elements.so my xml file is like this please look and help me what i want to add in this xml file..
-->
<LinearLayout
android:id="#+id/search_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<AutoCompleteTextView android:id="#+id/autocomplete_country"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:hint="Search"/>
</LinearLayout>
<!-- <ScrollView android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"> -->
<ListView android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/search_layout"
android:layout_centerHorizontal="true" />
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/orbit"
android:layout_below="#+id/listview"
/>
<!-- </ScrollView> -->
</RelativeLayout>
<!-- </ScrollView> -->
<!-- <RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"> -->
<!-- </RelativeLayout> -->
</LinearLayout>

add attribute android:layout_alignParentBottom="true" in your ImageView and add this in your ListView android:layout_above="#+id/imageViewId"

Nothing worked for me except adding the ImageView as Footer of ListView.
Better put your ImageView in a separate layout file and then inflate it programmatically and add it to the list as a footer view.
View footer = getLayoutInflater().inflate(R.layout.footer_image_view, null);
listView.addFooterView(footer);

Related

List view with custom items

I am developing an application and I need an explanation on how can I realize a listview made of custom items like this:
How can I organize things like that? And what should I use?
(Sorry for the poor quality of the image)
A basic design for ListView item could be something like this
<ListView>
<!-- container for the basic design -->
<LinearLayout
android:orientation="horizontal">
<!-- Left side column -->
<LinearLayout
android:orientation="vertical">
<ImageView />
<TextView />
</LinearLayout>
<!-- Right side column -->
<LinearLayout
android:orientation="vertical">
<TextView />
<!-- add Text and 3 images in this LinearLayout -->
<LinearLayout
android:orientation="horizontal" />
<TextView />
</LinearLayout>
</LinearLayout>
</ListView>
Then add your own custom adaptor to add the item in the ListView. Here is a good tutorial answer on SO: https://stackoverflow.com/a/6860788/2777098
You can use LinearLayout weigth.But its not recommended for performance.There are other ways.Like grid .
Your Custom list item shoul be like this.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.7"
android:background="#color/Black">
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1.3"
android:weightSum="2"
android:background="#color/Red">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1.6">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="0.4"
android:background="#color/Aqua">
</LinearLayout>
</LinearLayout>

Vertical RelativeLayout: how to achieve fixed header and footer and scrollable main area?

This is a layout I'm having problems with (this is for ListActivity):
<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" >
<TextView
android:id="#+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/path" />
<TextView
android:id="#android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#android:id/list" />
<Button
android:id="#+id/negative_button"
style="#style/Button"
android_alignParentBottom="true"
android:layout_below="#android:id/empty"
android:layout_weight="1" />
</RelativeLayout>
What happens right now is the list is below header TextView ("path") as it should be, the button is at the bottom also as it should be, but the ListView is not aligned between the header (textview) and footer (button). Instead, the button is simply slapped on top of listview. How can I fix that?
You need to define the footer and header before the list, try something like this:
<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" >
<TextView
android:id="#+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<!-- to see the button, you must to declare its width/height here
and not (as I think you did) in the style.xml -->
<Button
android:id="#+id/negative_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="#style/Button"
android:layout_alignParentBottom="true" />
<!-- also layout_weight doesnot change anything in RelativeLayout -->
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/path"
android:layout_above="#id/negative_button" />
<TextView
android:id="#android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#android:id/list" />
</RelativeLayout>
The TextView "empty" should not be below the TextView "empty".
If the Button must be at the bottom of the screen you can use
android:layout_alignParentBottom="true"
For the Button
Otherwise you can use this layout :
<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" >
<TextView
android:id="#+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<LinearLayout
android:id="#+id/container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/path">
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#android:id/empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#android:id/list" />
</LinearLayout>
<Button
android:id="#+id/negative_button"
style="#style/Button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/container" />
</RelativeLayout>
Or ever add the Button as a footer of you Listview :
mListView.addFooterView(mButton);
http://developer.android.com/reference/android/widget/ListView.html#addFooterView(android.view.View)
The only things that you used are the ListView, the first TextView as a "top bar" and the Button as a "bottom bar", right? If it is the case, why did you keep the empty TextView?
Try to remove it and try this layout:
<?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:orientation="vertical" >
<TextView
android:id="#+id/path"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<!-- work also with android:layout_height="0dip" -->
<Button
android:id="#+id/negative_button"
style="#style/Button"
android:layout_gravity="bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Saw on these questions, it might be help you:
1. Layout for ListView at top and Buttons in Bottom?
2. Android Layout with ListView between a "top bar" and "bottom bar"
3. Add a button in bottom of listview when the listview is empty (using ListActivity)
Hope this will be helpful and you'll have the expected result.

android unable to scroll image with ViewPager --> ScrollView --> Imageview

I am using a view pager inside my main view. Depending on the content of the frames I add one of two xml files. The first one is 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:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#ffffff"
android:layout_margin="6dip">
<!-- header -THIS is the source of the problem! -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:textSize="32dip"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- content -->
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true">
<TextView
android:text=""
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</ScrollView>
<!-- footer -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:text="Expires on..."
android:gravity="right"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
The alternative xml file is identical apart from the fact that the scrollview's child is an ImageView instead of a TextView.
Now, when using the textview all works fine. I can make use of the scrollview to scroll the text in the view up and down. However, when I use the layout with the imageview the image is frozen and the scrollview does not move it up and down.
Does anybody have any idea why this is??

problem adding linearlayout after listview

i am the new android development.i got one problem i.e. in my application i added listview for the activity.after listview i added one linear layout in that i took one imageview and textview.my problem is for this one it cannot show the last row in the emulator but it displays the imageview and textview.but its not displaying the last row of the listview.i cannot understand what is the problem having so can you know please help my xml code is below see it once....
-->
<LinearLayout
android:id="#+id/search_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<AutoCompleteTextView android:id="#+id/autocomplete_country"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="5dp"
android:singleLine="true"
android:hint="Search"/>
</LinearLayout>
<!-- <ScrollView android:id="#+id/scrollView1"
android:layout_width="wrap_content"
android:layout_height="match_parent"> -->
<ListView android:id="#+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/search_layout"
android:layout_centerHorizontal="true"
android:layout_above="#+id/ban_layout"/>
<!-- </ScrollView> -->
</RelativeLayout>
<!-- </ScrollView> -->
<!-- <RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"> -->
<!-- </RelativeLayout> -->
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#id/listview"
android:background="#android:color/black"
android:id="#+id/ban_layout">
<ImageView
android:src="#drawable/orbit"
android:layout_width="50dip"
android:layout_height="50dip"
android:scaleType="fitCenter"/>
<TextView android:text="TextView"
android:layout_width="fill_parent"
android:layout_height="60dip"
android:gravity="center"></TextView>
</LinearLayout>
Its because the your linear layout [ban_layout] is covering up your listview, as you have set it to align towards the bottom of the parent.
Quick Hacks,
Add an extra row and set its inside elements to invisible in your listview adapter
or
Add an bottom margin to your listview that compensates the footer
Your best solution would be to rework the parent relativelayout and set up a linearlayouts with weights

Android ListActivity - how to add a view below the ListView?

I'm trying to put a ProgressBar view below a ListView for a ListActivity. I want it to be always below the last row in the listView.
The ProgressBar, which is placed in a LinearLayout, does appear, as long as the list (which is filled by an adapter at runtime) is not exceeding the screen. As soon as the list is larger than the screen, the ProgressBar is no longer visible.
The layout xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/db1_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<!-- Title bar -->
<LinearLayout
style="#style/TitleBar" >
<TextView
style="#style/TitleBarText"
android:text="Some title text" />
<ImageButton
style="#style/TitleBarAction"
android:contentDescription="#string/description_search"
android:src="#drawable/title_search" />
</LinearLayout>
<!-- Content -->
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
<ListView
android:divider="#drawable/category_item_divider"
android:dividerHeight="#dimen/list_divider_height"
android:layout_height="wrap_content"
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_weight="1" />
<TextView
android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="#string/category_no_items" />
</LinearLayout>
<!-- Progress bar -->
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="wrap_content" >
<ProgressBar
android:id="#+id/productlist_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
Is this not possible with a LinearLayout? Any help appreciated.
You should add a footer using :
list.addFooterView(footerView);
or doing it manually, but then consider using relative layouts, there are far more powerfull than linear layouts. And then place your footer below the list, or better, place your list and your empty view above your footerview.

Categories

Resources