【问题标题】:Creating a list of TextViews with borders that match the list width in Android在 Android 中创建一个边框与列表宽度匹配的 TextView 列表
【发布时间】:2013-09-20 22:31:23
【问题描述】:

我正在尝试创建一个包含TextView 元素的 ListView,并且我希望列表的每一行都包含在一个矩形中。

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

-------
.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>

【问题讨论】:

  • 在你的 shape.xml 上尝试 android:layout_width="match_parent" android:layout_height="match_parent"

标签: android listview row listadapter


【解决方案1】:

在您的行矩形形状中,使用 layout_width 作为匹配父级或填充父级

【讨论】:

    猜你喜欢
    • 2021-07-03
    • 2022-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-04
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    相关资源
    最近更新 更多