Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List item width does not match parent inside dialog

I'm trying to make a simple listView with string objects only inside dialog; the problem is the list item is not width match_parent as i set:

enter image description here

the list view is the root element:

<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="#ff0000"
    android:id="@+id/lvLinks"
    android:layout_height="match_parent"/ >

list item:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:padding="7dp"
    android:textSize="15sp"
    android:background="#0000ff"
    android:layout_height="match_parent" />

adapter:

ListView lv = (ListView) findViewById(R.id.lvLinks);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,R.layout.list_item_links,items);
lv.setAdapter(adapter);

I've tested it on many OS, this is not the problem

FIXED: answer

<?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" >
    <ListView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:background="#ff0000"
        android:id="@+id/lvLinks"
        android:layout_height="match_parent" />
</LinearLayout>
like image 557
itzhar Avatar asked Jul 24 '15 11:07

itzhar


1 Answers

Why don't you put your ListView inside LinearLayout or RelativeLayout having width match_parent or fill_parent dialog.xml

like image 118
ULHAS PATIL Avatar answered Oct 16 '22 02:10

ULHAS PATIL