我的应用程序Listview中包含项,并为此项使用扩展BaseAdapter的适配器。滚动到底部时,其他项目的文本与另一个项目中的文本重叠。
这是Listview的布局代码。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragmentRulesLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="@+id/fragmentRulesFunctions_listView"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:layout_weight="1">
</ListView>
</FrameLayout>
这是此列表视图的项目代码
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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:id="@+id/ruleFunction_constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/ruleFunction_tvDeviceName"
app:layout_constraintWidth_percent = "0.6"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
初始化适配器
private void initRuleAdapter() {
ruleFunctionAdapter = new RuleFunctionAdapter(deviceWithFunctionalities,
getActivity());
listView = view.findViewById(R.id.fragmentRulesFunctions_listView);
listView.setAdapter(ruleFunctionAdapter);
}
和自定义适配器:
public View getView(int i, View view, ViewGroup viewGroup) {
itemView = view;
final DeviceWithFunctionalities dwf = deviceWithFunctionalities.get(i);
itemView = (itemView == null) ? inflater.inflate(R.layout.rule_function_item, null): itemView;
final TextView tvDeviceName = itemView.findViewById(R.id.ruleFunction_tvDeviceName);
tvDeviceName.setText(dwf.getName());
constraintLayout = itemView.findViewById(R.id.ruleFunction_constraintLayout);
if(dwf.getFunctionalities() != null) {
for (int j = 0; j < dwf.getFunctionalities().size(); j++) {
final TextView tvFunction = new TextView(itemView.getContext());
tvFunction.setId(TextView.generateViewId());
tvFunction.setText(dwf.getFunctionalities().get(j));
tvFunction.setTextSize(20);
tvFunction.setTypeface(null, Typeface.BOLD);
constraintLayout.addView(tvFunction);
ConstraintSet constraintSet = new ConstraintSet();
constraintSet.clone(constraintLayout);
constraintSet.connect(tvFunction.getId(), ConstraintSet.TOP, constraintLayout.getId(), ConstraintSet.TOP, (j) * 100 + 15);
constraintSet.connect(tvFunction.getId(), ConstraintSet.RIGHT, constraintLayout.getId(), ConstraintSet.RIGHT, 100);
constraintSet.applyTo(constraintLayout);
tvFunction.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SetRuleFunctionsFragment setRuleFunctionsFragment = new SetRuleFunctionsFragment();
Bundle bundle = new Bundle();
bundle.putString("DeviceName", tvDeviceName.getText().toString());
bundle.putString("DeviceFunction", tvFunction.getText().toString());
setRuleFunctionsFragment.setArguments(bundle);
FragmentManager fragmentManager = ((AppCompatActivity)context).getSupportFragmentManager();
fragmentManager.beginTransaction().
replace(R.id.content_frame, setRuleFunctionsFragment, setRuleFunctionsFragment.getTag()).
addToBackStack(null).commit();
}
});
}
}
我试图在Listview中使用
android:animateLayoutChanges="false"
但是它根本没有帮助
以下是问题的屏幕截图:text in item "test5"
真的需要帮助。谢谢!