gpt4 book ai didi

java - 我的 listView 中的项目没有正确对齐?

转载 作者:行者123 更新时间:2023-11-30 11:29:53 25 4
gpt4 key购买 nike

而不是解释发生了什么,here是屏幕截图:

如您所见,我的商品 list 遍及整个商店。将粘贴 activity_main.xml 和另一个格式化列表的 list_row.xml

ACTIVITY_MAIN.XML

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#121212">
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/logo" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/main_title"
android:textColor="#33b5e5"
android:background="#1f1f1f"
android:textStyle="bold"
android:textSize="14sp"/>
<ListView
android:id="@+id/android:list"
android:background="#121212"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:dividerHeight="2dip"/>
</LinearLayout>

LIST_ROW.XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip"
android:background="#121212">
<TableLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_height="fill_parent"
android:stretchColumns="*"
android:background="#121212">
<TableRow>
<ImageView
android:id="@+id/icon"
android:padding="2dip"
android:background="#121212"/>
<TextView
android:id="@+id/description"
android:padding="2dip"
android:textSize="18sp"
android:textColor="#ffffff"
android:singleLine="true"
android:background="#121212"/>
</TableRow>
</TableLayout>
</LinearLayout>

最佳答案

尝试按照您想要的比例为 ImageView 和 TextView 赋予权重,例如 android:layout_weight。并且不要忘记设置 android:layout_width = "match_parent"否则权重将无效..

关于java - 我的 listView 中的项目没有正确对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18076518/

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