我正在使用grIDvIEw来显示一些图像.我做了代码,但我仍然没有得到任何图像
定制适配器
public class CustomAdapter extends BaseAdapter { private Context context; private int[] images; public CustomAdapter(Context context, int[] images) { this.context = context; this.images = images; } @OverrIDe public int getCount() { return images.length; } @OverrIDe public Object getItem(int position) { return images[position]; } @OverrIDe public long getItemID(int position) { return position; } @OverrIDe public VIEw getVIEw(int position, VIEw convertVIEw, VIEwGroup parent) { VIEwHolder holder; if (convertVIEw == null) { holder = new VIEwHolder(); convertVIEw = LayoutInflater.from(context).inflate(R.layout.custom_trips_frag_row, parent, false);// holder.tvheader = (TextVIEw) convertVIEw.findVIEwByID(R.ID.tv_trips_home_header);// holder.tvDate = (TextVIEw) convertVIEw.findVIEwByID(R.ID.tv_trips_home_date); holder.ivImage = (ImageVIEw) convertVIEw.findVIEwByID(R.ID.iv_trips_home_image); convertVIEw.setTag(holder); } else { holder = (VIEwHolder) convertVIEw.getTag(); }// holder.ivImage.setimageResource(images[position]); return convertVIEw; } private class VIEwHolder { private TextVIEw tvheader; private TextVIEw tvDate; private ImageVIEw ivImage; }}
主要活动
public class MainActivity extends Masteractivity { private int[] images={R.drawable.images, R.drawable.images_2, R.drawable.images_1, R.drawable.images_4, R.drawable.images, R.drawable.images_2}; private GrIDVIEw grIDVIEw; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.trips_frag); grIDVIEw = (GrIDVIEw) findVIEwByID(R.ID.grID); grIDVIEw.setAdapter(new CustomAdapter(this, images)); }}
自定义行Xml
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="match_parent" androID:layout_height="match_parent"> <ImageVIEw androID:layout_wIDth="200dp" androID:layout_height="200dp" androID:ID="@+ID/iv_trips_home_image" androID:src="@drawable/images" androID:layout_alignParenttop="true" androID:layout_centerHorizontal="true" /> <!--<TextVIEw--> <!--androID:layout_wIDth="wrap_content"--> <!--androID:layout_height="wrap_content"--> <!--androID:layout_below="@+ID/iv_trips_home_image"--> <!--androID:layout_centerHorizontal="true"--> <!--androID:ID="@+ID/tv_trips_home_header" />--> <!--<triplogger.indIEhustlers.com.triplogger.UTIL.CustomTextVIEw--> <!--androID:layout_wIDth="wrap_content"--> <!--androID:layout_height="wrap_content"--> <!--androID:ID="@+ID/tv_trips_home_header"--> <!----> <!--androID:text="Berlin"--> <!--androID:textcolor="#000"--> <!--androID:textStyle="bold"--> <!--androID:textSize="@dimen/header_text"--> <!--androID:layout_below="@+ID/iv_trips_home_image"--> <!--androID:layout_centerHorizontal="true" />--> <!--<triplogger.indIEhustlers.com.triplogger.UTIL.CustomTextVIEw--> <!--androID:layout_wIDth="wrap_content"--> <!--androID:layout_height="wrap_content"--> <!--androID:text="14-Sept-2014"--> <!----> <!--androID:visibility="gone"--> <!--androID:textcolor="#23170e17"--> <!--androID:ID="@+ID/tv_trips_home_date"--> <!--androID:layout_below="@+ID/tv_trips_home_header"--> <!--androID:layout_centerHorizontal="true" />--></relativeLayout>
主要活动
public class Masteractivity extends Activity { protected Context activityContext; @OverrIDe protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activityContext = getApplicationContext(); }}
trips_frag
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:orIEntation="vertical" androID:layout_wIDth="match_parent" androID:layout_marginRight="@dimen/margin_right" androID:layout_marginleft="@dimen/margin_left" androID:layout_height="match_parent"> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:orIEntation="horizontal"> <ImageVIEw androID:layout_wIDth="0dp" androID:layout_height="match_parent" androID:layout_weight="1" androID:src="@drawable/tab" /> <ImageVIEw androID:layout_wIDth="0dp" androID:layout_height="match_parent" androID:layout_weight="1" androID:src="@drawable/tab" /> </linearLayout> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="match_parent" > <GrIDVIEw androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:numColumns="2" androID:ID="@+ID/grID" androID:verticalSpacing="5dp" androID:stretchMode="spacingWIDthUniform"></GrIDVIEw> </linearLayout></linearLayout>
表现
<?xml version="1.0" enCoding="utf-8"?><manifest xmlns:androID="http://schemas.androID.com/apk/res/androID" package="triplogger.indIEhustlers.com.triplogger"> <application androID:allowBackup="true" androID:icon="@drawable/ic_launcher" androID:label="@string/app_name" androID:theme="@style/TripLoggertheme"> <activity androID:name=".MainActivity" androID:label="@string/app_name"> <intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /> </intent-filter> </activity> </application></manifest>
我做了很多研究,但仍然没有取得任何成功
我没有得到我错的地方?请帮帮我
解决方法:
从grIDvIEw中删除androID:stretchMode =“spacingWIDthUniform”.
您已经在项目布局中修复了图像视图grIDitem的高度宽度
<?xml version="1.0" enCoding="utf-8"?><linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical" > <GrIDVIEw androID:ID="@+ID/grIDdata" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:numColumns="2" androID:stretchMode="spacingWIDthUniform" androID:verticalSpacing="5dp" > </GrIDVIEw></linearLayout>
GrIDItemLayout
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="vertical" > <ImageVIEw androID:ID="@+ID/iv_trips_home_image" androID:layout_wIDth="200dp" androID:layout_height="200dp" androID:layout_alignParenttop="true" androID:layout_centerHorizontal="true" /> <!-- <TextVIEw --> <!-- androID:layout_wIDth="wrap_content" --> <!-- androID:layout_height="wrap_content" --> <!-- androID:layout_below="@+ID/iv_trips_home_image" --> <!-- androID:layout_centerHorizontal="true" --> <!-- androID:ID="@+ID/tv_trips_home_header" /> --> <!-- <triplogger.indIEhustlers.com.triplogger.UTIL.CustomTextVIEw --> <!-- androID:layout_wIDth="wrap_content" --> <!-- androID:layout_height="wrap_content" --> <!-- androID:ID="@+ID/tv_trips_home_header" --> <!-- --> <!-- androID:text="Berlin" --> <!-- androID:textcolor="#000" --> <!-- androID:textStyle="bold" --> <!-- androID:textSize="@dimen/header_text" --> <!-- androID:layout_below="@+ID/iv_trips_home_image" --> <!-- androID:layout_centerHorizontal="true" /> --> <!-- <triplogger.indIEhustlers.com.triplogger.UTIL.CustomTextVIEw --> <!-- androID:layout_wIDth="wrap_content" --> <!-- androID:layout_height="wrap_content" --> <!-- androID:text="14-Sept-2014" --> <!-- --> <!-- androID:visibility="gone" --> <!-- androID:textcolor="#23170e17" --> <!-- androID:ID="@+ID/tv_trips_home_date" --> <!-- androID:layout_below="@+ID/tv_trips_home_header" --> <!-- androID:layout_centerHorizontal="true" /> --></relativeLayout>
总结 以上是内存溢出为你收集整理的android – GridView中的项目不可见全部内容,希望文章能够帮你解决android – GridView中的项目不可见所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)