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.
Related
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.
I'm Starting to get into Android programming more and more,
and right at the start I had a problem,
I'm creating a simple list with a costume layout and in the String array I'm passing to the string in the list, it some Data is to large to enter and thus, I'm left with a Cut string,
Is there a way to dynamically increase the list block height if the Data is too big to fit in it, so that it will wrap the list perfectly ?
I guess from my learning of code, you could calculate the string length and come up with a solution like that, but is there a more elegant way to fix this ?
Thank you
Use wrap_content on your list_item.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="wrap_content"
android:padding="5dp"
android:descendantFocusability="blocksDescendants">
<CheckBox..
</RelativeLayout>
or set height size
<?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="150dp"
android:padding="5dp"
android:descendantFocusability="blocksDescendants">
<CheckBox..
</RelativeLayout>
Fixed it by removing the alignment to the bottom of the Layout in the costume layout.
I Created GridView with CheckedTextView as item.
Here my Gridview in XML
<GridView
android:id="#+id/grid_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numColumns="auto_fit"
android:horizontalSpacing="5dip"
android:verticalSpacing="5dip"
android:gravity="center"
android:choiceMode="multipleChoice"/>
Here GridView item in XML
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/checkedTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/gray_color"
android:background="#drawable/shape_rectangle"/>
But it displaying two item in a row and each item displaying with extra space like below
how to avoid the extra space in each item in GridView ?
try using match_parent in the item's width & height, not sure what was the problem but ive also encountered this one, tell me if this fixed it, otherwise ill look into my old projects and get you another solution
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