[英]Android “ListView” items text overlapping and cut off
I'm trying to add buttons to a ListView of items so that a User can add specials to their "Favorites" by clicking a button/checkbox. 我正在尝试将按钮添加到项目的ListView中,以便用户可以通过单击按钮/复选框将特价添加到他们的“收藏夹”中。 Before adding this functionality, the layout of the list looked fine.
在添加此功能之前,列表的布局看起来不错。
Here is the "before" image: 这是“之前”图像:
Here is the "before" java code: 这是“之前”的Java代码:
ArrayList<Special> specials = specialda.getAllSpecialsByDay(selectedDay);
ListView listView = (ListView) findViewById(R.id.listView);
ArrayAdapter<Special> adapter = new ArrayAdapter<Special>(this, android.R.layout.simple_list_item_1, specials);
listView.setAdapter(adapter);
Now, after changing the Java code to this: 现在,将Java代码更改为此:
ArrayList<Special> specials = specialda.getAllSpecialsByDay(selectedDay);
ListView listView = (ListView) findViewById(R.id.listView);
ArrayAdapter<Special> adapter = new ArrayAdapter<Special>(this, android.R.layout.simple_list_item_multiple_choice, specials);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
listView.setAdapter(adapter);
I end up with this distorted view: 我最终得到了这种扭曲的观点:
Here is the xml layout file: 这是xml布局文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.yourfullname.flashcards.laxspecials.DisplaySpecials"
tools:showIn="@layout/activity_display_specials">
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</LinearLayout>
Any tips on what I am doing wrong or need to change? 关于我做错了或需要更改的任何提示吗?
Thanks 谢谢
EDIT: Here is up display_specials_button.xml file: 编辑:这是display_specials_button.xml文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
android:paddingRight="?android:attr/listPreferredItemPaddingRight"/>
</LinearLayout>
You can dublicate source of android.R.layout.simple_list_item_multiple_choice
performing necessary changes: 您可以复制
android.R.layout.simple_list_item_multiple_choice
源代码,以执行必要的更改:
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:textAppearance="?android:attr/textAppearanceListItemSmall"
android:gravity="center_vertical"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd" />
The difference is, that now you provide android:minHeight
and android:layout_height
in different way. 区别在于,现在您以不同的方式提供
android:minHeight
和android:layout_height
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.