我創建了擴展「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