Android ListView Layout center - android

I want to make a prayer time app in android as shown below. I try to make it using a Listview and background image but can not achieve it.

this is how you should go about it:
activity.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#drawable/your_image">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
In the parent set the background as your image, and populate listview with whatever data you like.

Related

Listview and TextView alignment

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>

Is It possible to click through a ListView?

I have a ListView over a LinearLayout. There are clickable elements in the LinearLayout and since the ListView is transparent I can see those elements, and would like to be able to click on them, but even though the ListView looks transparent, it behaves as a barrier and doesn't let me click on the elements.
Is there a way I can click through the ListView?
If I change the ListView layout_height to wrap_content, it behaves as I want, but I need it to start with a certain height, so the items will stack at the bottom with android:stackFromBottom="true".
This is an example of how the code looks like:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
(Clickable elements)
</LinearLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:transcriptMode="normal"
android:layout_marginTop="100dp"
android:layout_marginBottom="361dp"
android:stackFromBottom="true"
android:listSelector="#android:color/transparent"/>
</RelativeLayout>
Extend listview and override the onTouch() method and pass it down to the underlying views

Dynamic control inside a layout in android

I have an activity Which has Text to show then Some content under that then a list view.
While some content could be a picture, relative layout, Video control, or a linear layout. Depending upon the data it got from previous activity.
Is that possible to do that or I have to make separate layouts for all items?
You need a layout like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<FrameLayout
android:id="#+id/flSpecialContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</FrameLayout>
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
You can add any View you want in code to the FrameLayout (flSpecialContainer) based on what you need.
you can create all possible items in one layout and set visible and gone them depend on data you receive
in this case you don't need create them in code , and can preview activity layout in design mode.

Android: ListView Background color not applying to the whole listview

I have a custom ListView and I am trying to apply a background color on it but it only applies on the area where there is no list Item. I have tried many techniques but it won't working for me. I want to make the background color on the whole listview please help me how to achieve it.
Here is my XML code
<ListView
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:id="#+id/user"
android:scrollingCache="false"
android:scrollbars="none"
android:cacheColorHint="#00000000"
android:background="#android:color/darker_gray"
android:overScrollMode="never"
android:layout_below="#+id/sub_title">
</ListView>
This is its result
And this is what i want
Try using a transparent background color for your ListView items' layout, or use the same background color on your list items.
For the transparent background solution, you can apply this in your item's xml file
android:background="#android:color/transparent"
Please use 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"
android:background="#color/brown"
tools:context=".MainActivity" >
<ListView
android:id="#+id/programsLV"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</RelativeLayout>

Android. Set ListView's background Image

The following code is almost the same thing I want to achieve.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg">
<ListView android:layout_height="wrap_content" android:id="#+id/levelList" android:layout_width="match_parent" android:layout_alignParentLeft="true"></ListView>
</RelativeLayout>
I want to setup a background image for the whole ListView. The problem of this code is that background image blinks or disappears on scrolling.
I use sdk 2.2 and an emulator to run the program.
You'll want to set android:cacheColorHint="#00000000" on your ListView. This will set the cacheColorHint to transparent (notice the extra 2 0's after #000000) and fix your problem. Alternatively you can set the cacheColorHint to #android:color/transparent.
You should read this page on ListView backgrounds.

Categories

Resources