【发布时间】:2015-07-24 11:57:09
【问题描述】:
我正在尝试仅在对话框中使用字符串对象制作一个简单的 listView;问题是列表项不是我设置的宽度match_parent:
列表视图是根元素:
<?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>
【问题讨论】:
-
请提供有关如何创建对话框的代码。是
DialogFragment吗? -
我认为 textview 的主要布局是 wrap_content 所以它没有占用全宽所以检查一下。
-
我对 DialogFragment 有同样的问题,建议的答案不起作用