【问题标题】:android: listview item width fill_parent doesnt workandroid:listview项目宽度fill_parent不起作用
【发布时间】:2010-12-29 09:39:55
【问题描述】:

我已经搜索了互联网等,但找不到解决我的问题的方法。我正在创建一个列表视图并设置一个适配器:

myListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, theStringList));

theStringList 是一个带有项目的简单 LinkedList

android.R.layout.simple_list_item_1 是:

<TextView android:id="@android:id/text1" 
  android:layout_width="fill_parent" 
  android:layout_height="wrap_content" 
  android:textAppearance="?android:attr/textAppearanceLarge" 
  android:gravity="center_vertical" 
  android:paddingLeft="6dip" 
  android:minHeight="?android:attr/listPreferredItemHeight"/>;

问题:listView 项只适合文本而不适合整个屏幕?!?!?

【问题讨论】:

    标签: android listview


    【解决方案1】:

    您是如何创建ListView 的?它是在 XML 中定义的吗?您使用的是ListActivity 吗?还是您以编程方式创建它?您需要确保ListView 本身的宽度为fill_parent

    【讨论】:

      【解决方案2】:

      你的 TextView 的父视图是谁?检查那个的设置,也许它是一个小于屏幕的固定宽度或设置为“wrap_content”。

      【讨论】:

        【解决方案3】:

        如果您的ListViewConstraintLayout 内,就像我的情况一样,请尝试设置您的ListViewlayout_width=0dp(如其他布局中的match_parent)以匹配约束。

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        
            <ListView
                android:id="@+id/list_stocks"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:divider="@android:color/transparent"
                android:dividerHeight="3dp"
                android:padding="10dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/imageView4" />
        
        </androidx.constraintlayout.widget.ConstraintLayout>
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2013-10-26
          • 2012-09-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多