» »

[Android] Listview - problem z višino vrstice

[Android] Listview - problem z višino vrstice

icurk ::

Pozdravljeni,
zadnja dva dni se ubadam s sledečim problemom. Vrstica v Listview-u je vedno tako velika, kakor da bi nastavil lastnost vrstice layout_height = "wrap_content". Listview napolnim s custom adapterjem. Spodaj prilagam tudi del testne kode, ki mi dela probleme. Kot lahko vidite spodaj, bi morala moja vrstica biti visoka 150dp, vendar temu ni tako. Vse druge lastnoti vrstice, kot so barva texta, ozadje, padding itd. pa dela popolnoma normalno. V čem je torej trik?

hvala, lp

test.xml
<?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" >

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

activity class
@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.test);
		lv = (ListView) findViewById(R.id.listView1);

		array = new ArrayList<String>();
		array.add("prvi");
		array.add("drugi");
		array.add("tretji");
		array.add("Četrti");
		array.add("peti");
		array.add("šesti");

		CustomListViewAdapter adapter = new CustomListViewAdapter(this, array);
		lv.setAdapter(adapter);
		
	}

CustomListViewAdapter
public class CustomListViewAdapter extends BaseAdapter {

	private ArrayList<String> data;
	private Context context;
	LayoutInflater inflater;

	public CustomListViewAdapter(Context c, ArrayList<String> result) {
		this.data = result;
		this.context = c;
	}
        .
        .
        .
	public View getView(int position, View convertView, ViewGroup parent) {
		
		this.inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		String s = data.get(position);

		View vi = convertView;
		if (convertView == null)
			vi = inflater.inflate(R.layout.list_row, null);

		TextView tv = (TextView) vi.findViewById(R.id.tv1);
		tv.setText(s);

		return vi;
	}

}

List_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/krneki"
    android:layout_width="fill_parent"
    android:layout_height="150dp" 
    android:background="@android:color/white">

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:textColor="@color/dark_grey"
        android:textSize="@dimen/normal_Text" />

    <Button
        android:id="@+id/btnArrow"
        android:layout_width="18dp"
        android:layout_height="18dp"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:background="@drawable/arrow" />

</RelativeLayout>

c0dehunter ::

Poskusi namesto layout_height uporabiti layout_minHeight.

Poleg tega nastavi za vsako vrstico pravega parenta, ne null:

if (convertView == null)
            vi = inflater.inflate(R.layout.list_row, null);


spremeni v:

if (convertView == null)
            vi = inflater.inflate(R.layout.list_row, parent);
I do not agree with what you have to say,
but I'll defend to the death your right to say it.

icurk ::

O super... minHeight reši celotno zadevo :)
hvala


Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

[Android] Bluetooth aplikacija

Oddelek: Programiranje
51097 (960) marjan_h
»

Android - Začetnik

Oddelek: Programiranje
111794 (1119) hurlimannxt
»

[Android] setText iz AsyncTask

Oddelek: Programiranje
7853 (770) golobich
»

android črta

Oddelek: Programiranje
412411 (1682) g333kk
»

[Android]Cudno obnasanje aplikacije in emulatorja

Oddelek: Programiranje
71316 (1145) KernelPanic

Več podobnih tem