I have a ListView that is being populated with a custom adapter. I have a pretty basic layout for each row of the the ListView (not even sure if this is applicable to my question):
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
style="#style/BaseStyle"
android:orientation="vertical"
android:paddingLeft="5dip"
android:paddingRight="5dip"
android:paddingTop="8dip"
android:paddingBottom="8dip"
>
<TextView
android:id="#+id/text"
style="#style/BaseStyle.Title"
/>
</RelativeLayout>
I'd like to overlay a single TextView at the bottom of the ListView, but not entirely sure how as working with Android layouts can be an exercise in futility. :)
Wrap your main layout with a FrameLayout and put the view that you want to be in overlay as last child.
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/home_container"
android:layout_height="match_parent"
android:layout_width="match_parent">
...
your ListView
...
your text view (it is gonna be on top of your layout)
</FrameLayout>
From your description I am not sure that this is what you are looking for, you should give some more info in your question, let me know.
If instead you are just talking about the TextView inside each list item then you just need to specifiy the alignment in your text view:
android:layout_alignParentBottom="true"
Related
I have a listView which takes data from a rest API server and displays it. I need to add a textView on the side of it describing the type of data.
The right half of the screen has the listView and the left half has the textView.
The problem arises when the textView moves to accommodate the different screen sizes. I need the textView to be fixed and to be shown in conjunction with listView, and be in a straight line with the listView, regardless of the screen size. Cheers.
Edit: Image added of the sketch
It sounds like a ListView is not what you want to use. You cannot align Views with the children of a ListView. You would need to either put the TextViews within the ListView's children or not use a ListView.
The simplest way to do this would be a vertical LinearLayout containing many horizontal LinearLayouts.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="100dp"
android:layout_height="match_parent"/>
<Item that was in the ListView />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="100dp"
android:layout_height="match_parent"/>
<Item that was in the ListView />
</LinearLayout>
...
</LinearLayout>
The ListView is really for scrolling and when you don't know how many items there will be.
Perhaps you already have an adapter in which you are handling the creation of the items and that's why you are using a ListView. You can still create the LinearLayout's children programmatically by inflating each item individually and adding it to the container view.
Original Answer:
You probably want the TextViews to scroll with the ListView as well. So I would think you should use one ListView, then add the TextView to the left side of the ListView item.
You should use weightSum,
Here is an example.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2"
android:orientation="horizontal">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Hello World"/>
</LinearLayout>
here my xml layout of my Android app (where I show all of my contacts)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/android:empty"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dip"
android:layout_marginTop="5dip"
android:text="Scegli il contatto:"
/>
<EditText
android:id="#+id/editTextSend"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
I fill ListView using a custom Adapter.
But textView and Edit Text are not visibile. I want to show in particular edit text where users can write initial letters of his contacts name)
Suggestions to get them visible?
I fill ListView ... But textView and Edit Text are not visibile.
If you can only see a ListView then it appears you're using a ListActivity and forgot to call setContentView(). So you aren't actually using your layout... you only see ListActivity's default ListView.
That said, your XML code will work, but here are some quick notes:
As I stated in my comment, the TextView might be hidden depending on what type of Activity or Fragment you are using:
A ListActivity will automatically bind the #+id/android:empty and #+id/android:list Views, so the "empty" TextView is only shown when the ListView is empty.
An Activity won't recognize #+id/android:empty on its own. All the Views should be visible.
fill_parent is deprecated, simply use match_parent
Setting a ListView's height to wrap_content forces the Adapter to draw the ListView multiple times... with your layout I recommend using match_parent.
I'd say it is visible pretty fine with your layout. But anyway, I'd make listview declared that way:
<ListView
android:id="#+id/android:list"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" >
so it will take all the remaining free space
I have a list view but at the begining i want to place a piece of text that will help the users to understand what't the purpose of that list. After that i want to display the list and i want to be srollable. The scroll i know how to do it, but the text part no. I've tryed to make two layouts, one for the text and another for the list, but my xml instantly becomes fill with errors.
That's my xml
<?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="#drawable/legislatie1"
android:orientation="vertical" >
<ListView
android:id="#+id/listView1"
android:layout_width="wrap_content"
android:layout_height="600dp"
android:layout_alignParentRight="true"
android:drawSelectorOnTop="true"
android:textSize="10pt" >
</ListView>
</RelativeLayout>
You can use a static TextView above the ListView if you choose, but it will not scroll with the ListView. An alternative is to add a Header to your ListView, which will scroll with the list. Header Tutorial
I searched already but unfortunately found no real solution to this. I have added a footer to a listview with:
View footer = getLayoutInflater().inflate(R.layout.listfooter, null);
listview.addFooterView(footer);
The xml for the footer looks like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="#FFFFFFFF"
android:orientation="vertical"
android:layout_alignParentBottom="true"
android:background="#ee222222"
>
<TextView
android:id="#+id/info"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Test Test Test"
android:layout_alignParentBottom="true"
android:layout_gravity="center_vertical"
/>
</LinearLayout>
It does display a footer only as a single line
I change the number of rows in the list dynamically but I want the footer to always fill the rest of the listview if there are not enough items in it.
How can I do this?
Edit: I added an image, the left is how it is right now and the 2 on the right is what I want.
I can say the best solution can be for this problem is.
1) Create a XMl layout which must have hierarchy like this.
<Liniear Layout>
<ScrollView>
<LinearLayout>
<ListView>// add your list data here.
<\ListView>
<TextView><TextView>// for footer text
<\LinearLayout>
<ScrollView>
<LinearLayout>
Please let me kno if anything, I hope this approach will work as I tried it myself.
I create a listview and that listview has a header. I use addHeaderView() method. But when i scroll down in listview the scrollbar vanishes. Is there any way to avoid this i.e i want to show the header all the times, if scrolled still it will show.
To do that you can't do that with the addHeaderView() method.
If you want to place a header on top you should place that in the layout, something like this.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/titleBarText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Title"/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
The widget is behaving as intended. For what you need, you need to create a relativelayout with TextView at top followed by listview. The textview would act as the header and be static irrespective of your scroll.