<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<TextView
android:id="@+id/name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
android:textColor="@android:color/black"
android:textSize="17dip" />
<TextView
android:id="@+id/comment"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dip"
android:textColor="@android:color/black"
android:textSize="14dip" />
<TextView
android:id="@+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dip"
android:textColor="@android:color/black"
android:textSize="14dip" />
</LinearLayout>
This is my adapter:
public class MyArrayAdapter extends ArrayAdapter<Sample> {
private final Context context;
private final Sample[] samples;
public MyArrayAdapter(Context context, Sample[] samples) {
super(context, R.layout.row_layout, samples);
this.context = context;
this.samples = samples;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.row_layout, parent, false);
TextView name = (TextView) rowView.findViewById(R.id.name);
TextView comment = (TextView) rowView.findViewById(R.id.comment);
TextView date = (TextView) rowView.findViewById(R.id.date);
Sample sample = samples[position];
name.setText(sample.getName());
comment.setText(sample.getComment());
date.setText(sample.getDate());
return rowView;
}
}
But the problem is that the row height is not same for all rows.
How can I make the ListView with the same row height?
A:
ListView will adjust the row height to fit the content of the row. What you can do is set the minHeight attribute of the RowView:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip"
android:minHeight="50dp" >
This will set the minimum row height to 50dp.
Autore specializzato nel raccontare come funziona il mondo dei servizi locali e come trovare i professionisti migliori.