GridView控件的行间距,该怎么处理
1个回答
2017-11-19 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517181
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
GridView的属性设置:
<GridView android:id="@+id/gridView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:numColumns="3" > </GridView>
完成后计算缩略图,然后付给Adapter
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == TAKE_IMAGE) { if (resultCode == Activity.RESULT_OK) { Bitmap img = BitmapFactory.decodeFile(currentFilePath); GridView gv = (GridView) findViewById(R.id.gridView1); int cellWidth = gv.getWidth() / gv.getNumColumns(); float x = img.getWidth() / cellWidth; int thumbnailHeight = Math.round(img.getHeight() / x); Bitmap thumbnail = ThumbnailUtils.extractThumbnail(img, cellWidth, thumbnailHeight); ImageModel model = new ImageModel(); model.setFilePath(currentFilePath); model.setThumbnail(thumbnail); adapter.AddItem(model); adapter.notifyDataSetChanged(); } }}
adapter的GetView方法:
public View getView(int arg0, View arg1, ViewGroup arg2) { // TODO Auto-generated method stub ImageView view = null; if (arg1 == null) { view = new ImageView(context); GridView.LayoutParams param = new GridView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); view.setLayoutParams(param); view.setScaleType(ScaleType.CENTER_INSIDE ); view.setPadding(8, 8, 8, 8); } else { view = (ImageView) arg1; } view. setAdjustViewBounds(true); ImageModel model = imageList.get(arg0); view.setImageBitmap(model.getThumbnail()); return view;}
<GridView android:id="@+id/gridView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:numColumns="3" > </GridView>
完成后计算缩略图,然后付给Adapter
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == TAKE_IMAGE) { if (resultCode == Activity.RESULT_OK) { Bitmap img = BitmapFactory.decodeFile(currentFilePath); GridView gv = (GridView) findViewById(R.id.gridView1); int cellWidth = gv.getWidth() / gv.getNumColumns(); float x = img.getWidth() / cellWidth; int thumbnailHeight = Math.round(img.getHeight() / x); Bitmap thumbnail = ThumbnailUtils.extractThumbnail(img, cellWidth, thumbnailHeight); ImageModel model = new ImageModel(); model.setFilePath(currentFilePath); model.setThumbnail(thumbnail); adapter.AddItem(model); adapter.notifyDataSetChanged(); } }}
adapter的GetView方法:
public View getView(int arg0, View arg1, ViewGroup arg2) { // TODO Auto-generated method stub ImageView view = null; if (arg1 == null) { view = new ImageView(context); GridView.LayoutParams param = new GridView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); view.setLayoutParams(param); view.setScaleType(ScaleType.CENTER_INSIDE ); view.setPadding(8, 8, 8, 8); } else { view = (ImageView) arg1; } view. setAdjustViewBounds(true); ImageModel model = imageList.get(arg0); view.setImageBitmap(model.getThumbnail()); return view;}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询