改变细胞在网格视图的大小? [英] Changing the size of cells in grid view?

查看:153
本文介绍了改变细胞在网格视图的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Android的一个GridView是由从imagebuttons继承的自定义视图填充。

I have a gridview in Android which is populated by a custom view which inherits from imagebuttons.

我想要做的就是修改gridview的内部imagebuttons的大小以及细胞间的填充。

What I would like to do is modify the size of the imagebuttons inside the gridview as well as their padding between cells.

下面是我的getView()code,我一直使用的布局尝试,但不能因为我没有访问父视图: - /

Here is my getView() code, I've tried using layouts but can't because I don't have access to the parent view :-/

public View getView(int position, View convertView, ViewGroup parent) {

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (image == null)
            image = BitmapFactory.decodeResource(context.getResources(), R.drawable.dollar);

        ExpenseIcon ic = new ExpenseIcon(context);
        ic.setImageBitmap(image);

        return ic;
    }

我该怎么办呢?

推荐答案

您可以用的 setColumnWidth(INT) 或通过调用的 setNumColumns(INT)取决于您准确传达尝试。顺便说一句,你还可以设置,通过XML值(<一个href=\"http://developer.android.com/reference/android/widget/GridView.html#attr_android%3acolumnWidth\"相对=nofollow> 的android:columnWidth时 和的 的android:为numColumns

You can set the with with setColumnWidth(int) or set the column count by calling setNumColumns(int) depending on what you extactly trying. By the way you can also set that values by xml (android:columnWidth and android:numColumns).

有关您可以使用间隔<一个href=\"http://developer.android.com/reference/android/widget/GridView.html#attr_android%3ahorizontalSpacing\"相对=nofollow> 的android:horizo​​ntalSpacing 或<一个href=\"http://developer.android.com/reference/android/widget/GridView.html#setHorizontalSpacing%28int%29\"相对=nofollow> setHorizo​​ntalSpacing(INT) 和<一个href=\"http://developer.android.com/reference/android/widget/GridView.html#attr_android%3averticalSpacing\"相对=nofollow> 的android:verticalSpacing 或<一个href=\"http://developer.android.com/reference/android/widget/GridView.html#setVerticalSpacing%28int%29\"相对=nofollow> setVerticalSpacing(INT)

For the spacing you can use android:horizontalSpacing or setHorizontalSpacing(int) and android:verticalSpacing or setVerticalSpacing(int).

有关controling你需要改变你的 getView 函数解释第1条:

For controling the highe you need to change your getView function:

public YourConstructor() {
    // inflater should be a private member variable
    inflater = (LayoutInflater)context
                   .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // other code...
}

public View getView(int position, View convertView, ViewGroup parent) {
    if(convertView == null) {
        // create new one and put it into convertView. e.g.:
        convertView = new ExpenseIcon(context);
        AbsListView.LayoutParams lp = new AbsListView.LayoutParams(HEIGHT,WIDTH);
        convertView.setLayoutParams(lp);
    }

    // set the image to the currient convertView. e.g.:
    ((ExpenseIcon)convertView).setImageBitmap(image);

    return convertView;
}

这篇关于改变细胞在网格视图的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆