【发布时间】:2015-03-04 00:21:00
【问题描述】:
我在一个 android 应用程序中工作,我有一个包含 8 个图像的 GridView。我想将 GridView 添加为 ListView 的页脚。添加后,添加的页脚即GridView 仅显示 ListView 中的前两个图像,其余图像未显示在 ListView 中。我认为只显示了 GridView 的第一行。
请查看我的xml和代码
<GridView
android:layout_below="@+id/homescreen_top_RelativeLayout"
android:id="@+id/homescreen_gridview"
android:layout_margin="10dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="@dimen/gridViewcolumnWidth"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:numColumns="auto_fit"
android:layout_above="@+id/homescreen_logout"
android:stretchMode="columnWidth" />
public class ImageAdaptor extends BaseAdapter {
private Context mContext;
// Constructor
public ImageAdaptor(Context context) {
mContext = context;
}
public int getCount() {
return mImages.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if (convertView == null) {
// get layout from mobile.xml
gridView = inflater.inflate(R.layout.subrow_gridview, null);
// set image based on selected text
ImageView imageView = (ImageView) gridView
.findViewById(R.id.grid_item_image);
TextView textView = (TextView) gridView
.findViewById(R.id.grid_item_TextView);
imageView.setImageResource(mImages[position]);
gridView.setTag(position);
textView.setText(mImagesValues[position]);
} else {
gridView = (View) convertView;
}
return gridView;
}
// Keep all Images in array
public Integer[] mImages = { R.drawable.care, R.drawable.bus,
R.drawable.monthly_summary,R.drawable.care,R.drawable.care,R.drawable.care,R.drawable.care,R.drawable.care };
// Keep all Images in array
public String[] mImagesValues = { "Service " + "\n" + "Entry",
"Bus" + "\n" + "Attendance", "Monthly" + "\n" + "Summary","Monthly" + "\n" + "Summary","Monthly" + "\n" + "Summary","Monthly" + "\n" + "Summary","Monthly" + "\n" + "Summary" };
}
【问题讨论】:
-
为什么要做gridView = new View(mContext); ?
-
@2Dee。对不起。那是一个错误..我已经更新了我的代码。
-
@Vojtaaa9。不。。我的要求是在 gridview 中显示八个图像,并将该 gridview 添加为 listview 的页脚。
标签: android android-listview android-gridview