gpt4 book ai didi

android - 使用 ListAdapter 创建全角 View

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:16:07 24 4
gpt4 key购买 nike

我正在尝试在 ListView(通过 ListAdapter)中创建全宽 View 。这是当前的测试代码:

LinearLayout result = new LinearLayout(context);

TextView testView = new TextView(context);
testView.setText("Aaah");
TextView test2View = new TextView(context);
test2View.setText("Eeeeh");

result.addView(testView, new LinearLayout.LayoutParams(0,
LayoutParams.WRAP_CONTENT, 1));
result.addView(test2View, new LinearLayout.LayoutParams(0,
LayoutParams.WRAP_CONTENT, 1));

// To make it easier to see borders
result.setBackgroundColor(Color.BLUE);

(必须放在ListAdapter的createView中)

不幸的是,两个TextView很小,都卡在了左边。限制器实际上是结果 View 本身,而不是全宽,因此两个 TextView 只是共享这一小块空间。

有谁知道如何让它们全宽?谢谢 ! :)


编辑:简化(且几乎相同)的问题:


代码: http://pastebin.com/6pn1hXnT

我希望 TextView 是全角的,我将文本居中,这样我就可以看到它什么时候是全角的,什么时候只是包装内容。此代码在左侧显示文本,因此 MATCH_PARENT 未执行任何操作...

我该怎么办?

谢谢!

最佳答案

我遇到了类似的问题,我听从了关于这个 thread 的建议.链接的主题指的是对话框内的 ListView,但我在弹出列表中遇到过相同的行为。为了使 TextView 成为全角,我不得不将它包装在 RelativeLayout 中:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/
android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="14dip"
android:paddingRight="15dip"
>
<TextView
android:id="@+id/list_dialog_item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
/>
</RelativeLayout>

关于android - 使用 ListAdapter 创建全角 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4673577/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com