我创建了扩展“AdapterView <ListAdapter>”的类A,并创建了扩展“BaseAdapter”提供数据的D类。AdapterView项目不填充父项目
问题是,每个AdapterView项目没有将其长度延伸到AdapterView的长度,并且每个项目的长度不同,因为它与项目中文本的长度相同。我设置了所有可以设置为“FILL_PARENT”的布局参数,但这没有意义。
我应该检查哪一类? AdapterView子类或BaseAdapter子类,或AdapterView项目中的TextView子类? (我的TextView的子类来获得一些额外的效果)。
的getView方法:
public View getView(int position, View convertView, ViewGroup viewGroup) {
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(
R.layout.colselector_menu_item, null);
holder = new ViewHolder();
convertView.setTag(holder);
TextView tv = new VerticalTextView(viewGroup.getContext());
tv.setTextColor(Color.RED);
NewsInTimeApp app = (NewsInTimeApp) (((MainActivity) context)
.getApplication());
tv.setTextSize(Integer.parseInt(app.getConfig().get(
AppConfig.CFGNAME_UI_MAIN_COLSELECTOR_TEXTSIZE)));
((LinearLayout) convertView).addView(tv);
holder.groupItem = tv;
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.groupItem.setText(list.get(position).getName());
holder.collId = list.get(position).getId();
return convertView;
}
的colselector_menu_item.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#e1e1e1"
android:orientation="horizontal" >
<View
android:layout_width="1dp"
android:layout_height="fill_parent"
android:background="@android:color/darker_gray"/>
</LinearLayout>
检查所有这些。显示他们的代码也会有所帮助。 – Geobits
@Geobits至少有3个类和3个布局xml显示,看起来太乱了。我上传了快照:http://img38.imageshack.us/img38/606/9120120911103900.png蓝色视图是弹出窗口中的AdapterView,浅灰色视图是AdapterView项目。您可以看到AdapterView的高度大于任何项目的高度。 – realjin
对,但是你得到的是* wrap_content的*定义,所以有些东西没有被设置正确。检查所有的布局,特别是检查代码中的任何地方,以使它们膨胀。至少,从适配器的'getView'方法粘贴代码。无论你设置参数还是膨胀视图都可能是罪魁祸首,但是根本没有看到任何代码,它将不可能缩小范围。 – Geobits