2
已解决编辑:我已经解决了这个问题。它实际上并不符合逻辑,但除复选框之外,其他所有内容都必须是“Match_Parent”,而不是“Wrap_Content”(看起来很奇怪)。TextView在ListView中被自定义ArrayAdapter中断
我有我的自定义ArrayAdapter ListView中断文本内的问题。
一张图片胜过千言万语,所以这里的问题的一个画面:
正如你所看到的,第四线下被切断,在“裂痕”。
这里的自定义适配器代码:
public class CheckListAdapter extends ArrayAdapter<String>{
private int rowPadding = (int) getContext().getResources().getDimensionPixelSize(R.dimen.adapter_mediumRowVPadding);
private int medText = (int) getContext().getResources().getDimensionPixelSize(R.dimen.medium_text);
private Map<String,Boolean> map = new HashMap<String, Boolean>();
private List<String> content;
// Strings incoming are converted to a LinkedHashSet before being used.
// This ensures that the adapter content will not accidentally change,
// and that there is only one copy of a given string per adapter.
// A LinkedHashSet is a HashSet with a predictable iteration order.
public CheckListAdapter(Context context, int resource, List<String> objects) {
super(context, resource, new ArrayList<String>(new LinkedHashSet<String>(objects)));
}
public CheckListAdapter(Context context, List<String> objects) {
this(context, android.R.layout.simple_list_item_1, objects);
}
public CheckListAdapter(Context context, String[] objects) {
this(context, android.R.layout.simple_list_item_1, Arrays.asList(objects));
}
@Override
public View getView(final int position, View convertView, ViewGroup parent){
LinearLayout row = new LinearLayout(this.getContext());
row.setBackgroundResource(R.drawable.greenclicked_background);
row.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
final CheckBox check = new CheckBox(getContext());
check.setButtonDrawable(R.drawable.gemsgreen_btn_check_holo_light);
final TextView text = new TextView(getContext());
LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, Gravity.FILL);
text.setLayoutParams(params);
text.setGravity(Gravity.TOP | Gravity.LEFT);
final String item = this.getItem(position);
if(!this.map.containsKey(item)){
this.map.put(item, false);
}
else{
boolean checked = map.get(item);
check.setChecked(checked);
}
row.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
boolean checked = map.get(item);
checked = !checked;
map.put(item, checked);
check.setChecked(checked);
}
});
text.setText(item);
text.setMinLines(1);
text.setMaxLines(10);
row.addView(check);
row.addView(text);
row.setPadding(0, rowPadding, 0, rowPadding);
return row;
}
public Map<String,Boolean> getResults(){
return map;
}
}
这里有一个自定义的ListView代码:我一直在寻找这个问题的解决方案了差不多一个小时
public class NonScrollListView extends ListView {
public NonScrollListView(Context context) {
super(context);
}
public NonScrollListView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public NonScrollListView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom);
ViewGroup.LayoutParams params = getLayoutParams();
params.height = getMeasuredHeight();
}
}
,我完全没有运气。我已经尝试了许多不同的方法,使用不同的重力和布局参数设置,但是没有任何东西使它看起来与它在屏幕截图中显示的方式不同。
这完全不适用 - 与我在OP中发布的结果完全相同。 –