我正在尝试制作一个仅在对话框内包含字符串对象的简单 listView;问题是列表项不是我设置的宽度 match_parent
:
ListView 是根元素:
<?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"/ >
列表项:
<?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" />
适配器:
ListView lv = (ListView) findViewById(R.id.lvLinks);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context,R.layout.list_item_links,items);
lv.setAdapter(adapter);
我在很多操作系统上测试过,这不是问题
已修复: 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>
最佳答案
为什么不将 ListView 放在宽度为 match_parent 或 fill_parent dialog.xml 的 LinearLayout 或 RelativeLayout 中
关于android - 列表项宽度与对话框内的父级不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31609979/