gpt4 book ai didi

android - ListView 项目问题

转载 作者:行者123 更新时间:2023-11-30 04:37:14 26 4
gpt4 key购买 nike

我的自定义 ListView 有问题。列表中的项目不适合列表的宽度,我不知道为什么。

也许图片对你有帮助。

enter image description here

ListView :

  android:layout_width="match_parent"
android:layout_height="match_parent" android:orientation="vertical">
<LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="match_parent" android:gravity="center_vertical" android:background="#626262">
<AutoCompleteTextView android:id="@+id/autoCompleteTextView1" android:layout_width="match_parent" android:layout_weight="2" android:layout_height="45dip" android:layout_marginTop="2dip"></AutoCompleteTextView>
<ImageView android:id="@+id/imageView1" android:src="@drawable/lupe" android:layout_width="wrap_content" android:layout_height="wrap_content"></ImageView>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout2" android:layout_width="wrap_content" android:layout_height="match_parent">
<ListView
android:id="@+id/android:list"
android:background="#000000"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:cacheColorHint="#FFFFFF"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>

行:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<ImageView
android:id="@+id/image"
android:layout_width="50dip"
android:layout_height="50dip"
android:src="@drawable/icon"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/Buddystoptext"
android:layout_height="wrap_content"
android:layout_gravity="left|center_vertical"
android:textSize="20dip"
android:layout_marginLeft="10dip"
android:text="Text"
android:layout_width="match_parent" />
</LinearLayout>

点击 xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Non focused states -->
<item android:state_focused="false"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/msg_bg_deselect" />
<item android:state_focused="false"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/msg_bg_focus" />
<!-- Focused states -->
<item android:state_focused="true"
android:state_selected="false"
android:state_pressed="false"
android:drawable="@drawable/msg_bg_deselect" />
<item android:state_focused="true"
android:state_selected="true"
android:state_pressed="false"
android:drawable="@drawable/msg_bg_focus" />
<!-- Pressed -->
<item android:state_pressed="true"
android:drawable="@drawable/msg_bg_focus" />
</selector>

有人可以帮忙吗?

谢谢。

最佳答案

您项目的布局应将 layout_width 设置为 fill_parent 而不是 wrap_content。

关于android - ListView 项目问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6635512/

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