custom design ui a listview in android - android

I have a ListView in my project . How I can custom design it according to below picture (between each row and next row must be exist a gap or a space and color each row must be different by background of ListView )
<?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">
<ListView
android:id="#+id/hadis_lsv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</ListView>
</RelativeLayout>

You should give padding to your RelativeLayout or margin to ListView for gaps or space between Listview.
And for background changes make two ListView for bind in recyclerview. Then put a condition on your onBindView to bind specific ListView.

Related

Remove left space between ListView border and Items

Can somebody tell me how can I remove the space between the listview border and the items inside the listview?
Remove margins from your xml listview layout.
If I understand your question properly, you are not looking for removing space between listview border and items (The red sign on your image says that! you want to remove space between two elements inside 1 item). If that is true, then you have to go to the custom layout file you created to set as a row for the listview. It looks like you have 2 TextViews there ("Go" and "Bro1, Bro2......"). There you have to play with the Margin-Up and Margin-Bottom of these 2 textviews.
android:layout_marginBottom="1dp"
android:layout_marginUp="1dp"
If you mean the space around the listview then either check the margins of the listview or paddings of the parent layout of the listview.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="0dp">
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp" />
</LinearLayout>
</RelativeLayout>

Android - Create a ribbon on top of a row of a Recycler View?

As shown in the below image, I want to create a Recyclerview with each row/ card view showing "Sale" in a ribbon style wrapped over the row. I have already created the recyclerview and populated the data. Only the "Sale" ribbon is not coming.
How do I do it?
You should use RelativeLayout for this task.
Put your card's content into a LinearLayout (call contentView this time) and give it some layout_margin. Then put this content view into a RelativeLayout and add the sale ribbon as an ImageView child element.
Like 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:background="#color/white">
__content_of_the_card__
</LinearLayout>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ribbon"/>
</RelativeLayout>

How to add an explanatory text before a list view in android?

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

Listview height

I have listview that loads all audio files from sd card...there is alot of files..but listview looks prety bad..every row height automatically resizes depends of item name that shows in row..background is white and text is grey so it is hard to notice it...I want to set every row height to same so it looks like this
here is my code
<?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">
<ListView
android:id="#+id/PhoneMusicList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</ListView>
</LinearLayout>
In your group row.xml
Instead of android:layout_height="wrap_content" for the listview row height give a fixed height..This will solve your problem......
Something like this
android:layout_height="50dp"
Use the customize list view. Create a layout for one list view item. Set the height in that. Apply adapter in .java file. Then it works fine. I done the same thing and it works for me.

Scrolled but till header visible in listview in android

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.

Categories

Resources