在Android中创建边框与列表宽度匹配的文本视图列表

在Android中创建边框与列表宽度匹配的文本视图列表,android,listview,row,listadapter,Android,Listview,Row,Listadapter,我试图创建一个包含TextView元素的列表视图,我希望列表中的每一行都包含在一个矩形中 当列表出现时,问题就出现了,行(矩形)与其内容相匹配,而不是其父ListView。我最终得到了这样的东西: ------- .hello. ------------- .How are you. ------------- ------------- .hello . ------------- .How are you. ------------- 我想要这样的东西: ------- .he

我试图创建一个包含
TextView
元素的列表视图,我希望列表中的每一行都包含在一个矩形中

当列表出现时,问题就出现了,行(矩形)与其内容相匹配,而不是其父
ListView
。我最终得到了这样的东西:

-------
.hello.
-------------
.How are you.
-------------
-------------
.hello      .
-------------
.How are you.
-------------
我想要这样的东西:

-------
.hello.
-------------
.How are you.
-------------
-------------
.hello      .
-------------
.How are you.
-------------
这是我的行元素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="horizontal" 
    android:background="@layout/popup_lonely_row">

    <TextView
        android:id="@+id/promo_row_text"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="2dp"
        android:text="Lorem ipsum dolorem sit amet"
        android:textColor="@color/dark_gray_options" />
</LinearLayout>

这是行矩形形状xml:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="5dp"
    android:shape="rectangle" >

    <solid android:color="#FFFFFF" />

    <stroke
        android:width="1dp"
        android:color="@color/blue_alert_stroke" />

</shape>

在行矩形形状中,使用layout\u width作为匹配父项或填充父项

尝试在shape.xml上使用android:layout\u width=“match\u parent”android:layout\u height=“match\u parent”