0

I am trying to build an Application where there is a list-view with many items but I am not being able to change or set the width and height of single items.I have searched everywhere and the answer I got is making the width fill_parent,but its not working for me...

Kindly help.... thanks in advance... here are codes:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginRight="3dp"
    tools:context=".CustomListViewAndroidExample" >

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="match_parent" 
        android:layout_weight="1"/> 

</RelativeLayout>
user3736518
  • 75
  • 1
  • 2
  • 12
  • where is your list adapter views ( the views that u want to add to your listview) ? post the xml code and your adapter class too – Kosh Jun 17 '14 at 06:24

2 Answers2

1

If you want to change the height of list view dynamically, you can use

list.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,    theSizeIWant)); 

or

import android.view.ViewGroup.LayoutParams;
ListView mListView = (ListView)   findViewById(R.id.listviewid);
LayoutParams list = (LayoutParams) mListView.getLayoutParams();
list.height = set the height acc to you;//like int  200
mListView.setLayoutParams(list);
Wilson
  • 176
  • 1
  • 11
0

This link shows you how to do it in java with your own custom adapter.

When overriding the getView() in your adapter, your can modify the height before supplying your view to the framework for render. Also, note that you do not have to use a SimpleCursorAdapter, an ArrayAdapter can also be used in the same fashion.

final SimpleCursorAdapter adapter = new SimpleCursorAdapter (context, cursor) {
    @Override
    public View getView (int position, View convertView, ViewGroup parent) {
        final View view = super.getView(position, convertView, parent);
        final TextView text = (TextView) view.findViewById(R.id.tvRow);
        final LayoutParams params = text.getLayoutParams();

        if (params != null) {
                params.height = mRowHeight;
        }

        return view;
    }
}
Community
  • 1
  • 1
Ryhan
  • 1,815
  • 1
  • 18
  • 22