I have search the internet and so on but couldnt find a solution for my problem. I'm creating a listview and setting an adapter:
myListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, theStringList));
theStringList is a simple LinkedList<String> with items.
and the android.R.layout.simple_list_item_1
is:
<TextView android:id="@android:id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_co开发者_StackOverflow社区ntent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"/>;
problem: the listView items only fit the text but NOT the whole screen?!?!?
How are you creating your ListView
? Is it defined in XML? Are you using a ListActivity
? Or are you creating it programmatically? You need to make sure that the ListView
itself has a width of fill_parent
.
Who is the parent view of your TextView? Check the settings for that one too, maybe it's a fixed width smaller than the screen or seted to "wrap_content" .
If your ListView
is inside ConstraintLayout
, as it is in my case, try setting your ListView
's layout_width=0dp
(like match_parent
in other layouts) to match the constraint.
<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>
精彩评论