GridView具有相等的行

时间:2015-05-28 11:57:33

标签: android gridview

我有一个2行3列的gridview。想要在屏幕上平均拉伸行,而无需用户屏幕查看任何行。行应该具有相同的高度(最好是gridview / 3的高度)。

目前使用此适配器:

public class HomeAdapter extends BaseAdapter {


    private LayoutInflater mLayoutInflater;
    private Context mContext;
    private int h;

    public HomeAdapter(Context context, int height) {
        mContext = context;
        mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        h = height;
    }

    @Override
    public int getCount() {
        return 6;
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }


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

        FunctionHolder holder;
        if (convertView == null) {
            holder = new FunctionHolder();
            convertView = mLayoutInflater.inflate(R.layout.view_flipper, parent, false);
            holder.flipper = (ViewFlipper) convertView.findViewById(R.id.flipper);

        } else {
            holder = (FunctionHolder) convertView.getTag();
        }


        View topView = mLayoutInflater.inflate(R.layout.first_item, null);
        View bottomView = mLayoutInflater.inflate(R.layout.second_item, null);

        changeView(bottomView, position);
        changeView(topView, position);

        holder.flipper.addView(topView, 0);
        holder.flipper.addView(bottomView, 1);

        startAnimation(holder.flipper, position);
        convertView.setMinimumHeight(h);
        convertView.setTag(holder);

        return convertView;
    }

gridview.xml

<?xml version="1.0" encoding="utf-8"?>

<GridView
    android:drawSelectorOnTop="true"
    android:listSelector="@drawable/list_bg"
    android:verticalSpacing="5dp"
    android:horizontalSpacing="5dp"
    android:padding="5dp"
    android:columnWidth="100dp"
    android:numColumns="2"
    android:stretchMode="columnWidth"
    android:gravity="center"
    android:id="@+id/home_grid"
    android:layout_width="match_parent"
    android:layout_height="match_parent"></GridView>

1 个答案:

答案 0 :(得分:0)

试试这个

$csp = (isset($_GET['csp']) ? $_GET['csp'] : 10);

然后根据设备的高度动态设置 public static int getScreenHeight(Context c) { if (screenHeight == 0) { WindowManager wm = (WindowManager) c.getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); Point size = new Point(); display.getSize(size); screenHeight = size.y; } return screenHeight; } 项目的高度

GridView