android - 列表项宽度与对话框内的父级不匹配

标签 android android-listview

我正在尝试制作一个仅在对话框内包含字符串对象的简单 listView;问题是列表项不是我设置的宽度 match_parent:

enter image description here

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/

相关文章:

java - 如何从迭代器获取 url?

android - ListView 的自定义单元格与 API9 中的父级宽度不匹配

android - 按下 ListView 项目时播放声音

java - 如何使用适配器填充ListView

Android - 多列 ListView

Android SQLite onUpgrade = 强制关闭

java - 从 Facebook 下载用户个人资料图片 : AsyncTask or HandlerThread

android - 从 Google Play 开发者控制台中的库中删除 APK

android - Monodroid 以编程方式从 Fragment 更改 Activity Title

Android- Listview- 按钮