<GridVew 高度自适应>设置GirdView中item高度来填满 达到自适应

GridView高度和宽度只能在Adapter中获取,所以设置每项item的代码要写在Adapter中。

代码如下:

int height = mGridView.getHeight();
int width = mGridView.getWidth(); 

//得到GridView每一项的高度与宽度
GridView.LayoutParams params = new GridView.LayoutParams(width / 3,
                 height /2);
//设置每一行的高度和宽度
view.setLayoutParams(params);

使用此方法每个Item都将多绘制一遍,GirdView项不会太多可以使用,如果数据量大挺影响性能的,如果大家发现更好或优化的方法,给我留言。

时间: 2024-08-29 04:27:04

<GridVew 高度自适应>设置GirdView中item高度来填满 达到自适应的相关文章

如何设置listview每个item高度

据我所了解,listview每行的宽度是由 inflater填充布局中高度最大的那个控件的高度... public  void setListViewHeightBasedOnChildren(ListView listView)         {                //获取ListView对应的Adapter                ListAdapter listAdapter = listView.getAdapter();                if (lis

GridView中item高度自适应

public class MyAdapter extends BaseAdapter {         GridView mGv;        public static int ROW_NUMBER = 5;     public MyAdapter (GridView gv, Context mContext, ArrayList<String> list) {         this.context = mContext;         this.mGv = gv;       

设置TableViewer 中的高度和宽度

//此处的Table就是读者所使用的table //此处本人所使用的table  是通过 tableViewer.getTable();来的 读者可自行做转换 Table.addListener(SWT.MeasureItem, new Listener() { @Override public void handleEvent(Event event) { // TODO 自动生成的方法存根 // 设置宽度 event.width = soluTable.getGridLineWidth();

list view item高度设置

如何设置list view中的item的高度呢? 示例如下: <?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=&qu

6.设置ListView的Item的高度无效

问题: 设置ListView的Item的高度无效. 解决方式: 设置ListView的Item的minHeight属性.

iOS7中Cell高度 Label高度自适应

? 1 2 3 4 5 6 7 8 9 10 11 12 ?- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{     NSString *str = [_dataArray objectAtIndex:indexPath.row];     UIFont *tfont = [UIFont systemFontOfSize:14.0];     NSDictio

获取textarea文本框所选字符光标位置索引,以及选中的文本值;textarea高度自适应,随着内容增加高度增加;获取输入框中的光标位置

获取textarea文本框所选字符光标位置索引,以及选中的文本值 $.fn.selection = function () { var s, e, range, stored_range; if (this[0].selectionStart == undefined) { var selection = document.selection; if (this[0].tagName.toLowerCase() != "textarea") { var val = this.val()

WPF中RichTextBox高度自适应问题解决方法

最近做一个项目需要用到RichTextBox来显示字符串,但是不允许出现滚动条,在RichTextBox宽度给定的条件下,RichTextBox的高度必须正好显示内容,而不出现下拉滚动条. 这样就要计算要显示的文本的高度,在网上找了许久,其中使用了FormattedText类来计算文本的高度,发现FormattedText计算出的高度总是比RichTextBox需要的高度小. 在网上找到,可自定义一个控件,继承System.Windows.Controls.RichTextBox. privat

CSS - Select 标签在不同浏览器中的高度设置

当使用Select标签时,在不同浏览器中显示的高度不同,如何解决此问题: 解决方法链接:http://stackoverflow.com/questions/20477823/select-html-element-with-height Demo:http://jsfiddle.net/64px3yg5/1/ HTML: <select> <option>Here's one option</option> <option>here's another o