Example usage for android.widget GridView setColumnWidth

List of usage examples for android.widget GridView setColumnWidth

Introduction

In this page you can find the example usage for android.widget GridView setColumnWidth.

Prototype

public void setColumnWidth(int columnWidth) 

Source Link

Document

Set the width of columns in the grid.

Usage

From source file:org.alfresco.mobile.android.application.fragments.GridAdapterHelper.java

public static int getDisplayItemLayout(FragmentActivity activity, GridView gv, int displayMode) {
    int displayItemLayout = R.layout.row_large_tile_single_line;

    if (activity instanceof PublicDispatcherActivity || activity instanceof PrivateDialogActivity
            || activity instanceof BaseShortcutActivity) {
        gv.setColumnWidth(DisplayUtils.getDPI(activity.getResources().getDisplayMetrics(), 1000));
        return R.layout.row_large_tile_single_line;
    }// www. j  a v  a  2  s  .co m

    switch (displayMode) {
    case DISPLAY_LIST:
        gv.setColumnWidth(DisplayUtils.getDPI(activity.getResources().getDisplayMetrics(), 240));
        displayItemLayout = R.layout.row_large_tile_single_line;
        break;
    case DISPLAY_LIST_LARGE:
        gv.setColumnWidth(DisplayUtils.getDPI(activity.getResources().getDisplayMetrics(), 320));
        displayItemLayout = R.layout.row_two_lines_progress;
        break;
    case DISPLAY_GRID:
        gv.setColumnWidth(DisplayUtils.getDPI(activity.getResources().getDisplayMetrics(), 240));
        displayItemLayout = R.layout.row_two_lines_progress;
        break;
    default:
        break;
    }
    return displayItemLayout;
}

From source file:com.bilibili.socialize.share.utils.selector.BaseSharePlatformSelector.java

protected static GridView createShareGridView(final Context context,
        AdapterView.OnItemClickListener onItemClickListener) {
    GridView grid = new GridView(context);
    ListAdapter adapter = new ArrayAdapter<ShareTarget>(context, 0, shareTargets) {
        // no need scroll
        @Override//from   w  w w  .j a  v  a2 s  .c  o m
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.bili_socialize_shareboard_item, parent, false);
            view.setBackgroundDrawable(null);
            ImageView image = (ImageView) view.findViewById(R.id.bili_socialize_shareboard_image);
            TextView platform = (TextView) view.findViewById(R.id.bili_socialize_shareboard_pltform_name);

            ShareTarget target = getItem(position);
            image.setImageResource(target.iconId);
            platform.setText(target.titleId);
            return view;
        }
    };
    grid.setNumColumns(-1);
    grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    grid.setColumnWidth(context.getResources().getDimensionPixelSize(R.dimen.bili_socialize_shareboard_size));
    grid.setLayoutParams(new ViewGroup.LayoutParams(-1, -2));
    grid.setSelector(R.drawable.bili_socialize_selector_item_background);
    grid.setAdapter(adapter);
    grid.setOnItemClickListener(onItemClickListener);
    return grid;
}

From source file:com.chale22.ico01.iconfragment.IconFragmentGames.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.icon_main, container, false);
    int iconSize = getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
    GridView gridview = (GridView) view.findViewById(R.id.icon_grid);
    gridview.setNumColumns(4);/*w  w  w  . j a  v a2 s .c  o  m*/
    gridview.setColumnWidth(iconSize);
    gridview.setStretchMode(GridView.STRETCH_SPACING_UNIFORM);
    gridview.setVerticalSpacing(iconSize / 2);
    gridview.setOnItemClickListener(this);
    gridview.setAdapter(new IconAdapter(getActivity(), iconSize));
    gridview.setOnItemClickListener(this);
    CONTENT_URI = Uri.parse("content://" + iconsProvider.class.getCanonicalName());
    return view;

}

From source file:it.gcaliendo.elytheme.iconfragment.IconFragmentGames.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.icon_main, container, false);
    int iconSize = getResources().getDimensionPixelSize(android.R.dimen.app_icon_size);
    GridView gridview = (GridView) view.findViewById(R.id.icon_grid);
    gridview.setNumColumns(4);/*from   w  ww .jav  a  2s .c  o  m*/
    gridview.setColumnWidth(iconSize);
    gridview.setStretchMode(GridView.STRETCH_SPACING_UNIFORM);
    gridview.setVerticalSpacing(iconSize / 2);
    gridview.setOnItemClickListener(this);
    gridview.setAdapter(new IconAdapter(getActivity(), iconSize));
    gridview.setOnItemClickListener(this);
    CONTENT_URI = Uri.parse("content://" + IconsProvider.class.getCanonicalName());
    return view;

}

From source file:com.rsatyavolu.nanodegree.popularmovies.MainActivityFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.fragment_main, container, false);

    GridView gridView = (GridView) rootView.findViewById(R.id.gridview);
    gridView.setColumnWidth(200);

    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//w  w  w .ja  va2 s.co m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (parent.getItemAtPosition(position) != null) {
                ((Callback) getActivity()).onItemSelected(movieListAdapter.getItem(position));
            }
        }
    });

    if (savedInstanceState != null) {
        data = (List<MovieItemModel>) savedInstanceState.getSerializable(MOVIE_SEARCH_RESULTS);
    } else {
        data = new ArrayList<MovieItemModel>();
    }

    movieListAdapter = new MovieIconViewAdapter(getActivity(), data);
    gridView.setAdapter(movieListAdapter);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    PreferenceManager.setDefaultValues(getActivity(), R.xml.pref_settings, false);
    String apiToken = prefs.getString(getString(R.string.pref_api_token_key), "");
    String sortOption = prefs.getString(getString(R.string.pref_sort_key), "");

    if (apiToken.length() <= 25) {
        Intent settings = new Intent(getActivity(), SettingsActivity.class);
        startActivity(settings);

        return rootView;
    }

    if (data.size() == 0) {
        DiscoverMoviesTask discoverMoviesTask = new DiscoverMoviesTask();
        discoverMoviesTask.execute(DISCOVER_MOVIES_URL, apiToken, sortOption);
    }

    return rootView;
}

From source file:br.com.bioscada.apps.biotracks.fragments.ChooseActivityTypeDialogFragment.java

public static Dialog getDialog(final Activity activity, final String category,
        final ChooseActivityTypeCaller caller) {
    View view = activity.getLayoutInflater().inflate(R.layout.choose_activity_type, null);
    GridView gridView = (GridView) view.findViewById(R.id.choose_activity_type_grid_view);
    final View weightContainer = view.findViewById(R.id.choose_activity_type_weight_container);

    TextView weightLabel = (TextView) view.findViewById(R.id.choose_activity_type_weight_label);
    weightLabel.setText(PreferencesUtils.isMetricUnits(activity) ? R.string.description_weight_metric
            : R.string.description_weight_imperial);

    final TextView weight = (TextView) view.findViewById(R.id.choose_activity_type_weight);

    List<Integer> imageIds = new ArrayList<Integer>();
    for (String iconValue : TrackIconUtils.getAllIconValues()) {
        imageIds.add(TrackIconUtils.getIconDrawable(iconValue));
    }/*from  w  ww  .j  a  va 2  s .  c o  m*/

    Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(activity.getResources(), R.drawable.ic_track_airplane, options);
    int padding = 32;
    int width = options.outWidth + 2 * padding;
    int height = options.outHeight + 2 * padding;
    gridView.setColumnWidth(width);

    final ChooseActivityTypeImageAdapter imageAdapter = new ChooseActivityTypeImageAdapter(activity, imageIds,
            width, height, padding);
    gridView.setAdapter(imageAdapter);

    final String weightValue = StringUtils.formatWeight(PreferencesUtils.getWeightDisplayValue(activity));
    final AlertDialog alertDialog = new AlertDialog.Builder(activity)
            .setNegativeButton(R.string.generic_cancel, null)
            .setPositiveButton(R.string.generic_ok, new Dialog.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    boolean newWeight = false;
                    if (weightContainer.getVisibility() == View.VISIBLE) {
                        String newValue = weight.getText().toString();
                        if (!newValue.equals(weightValue)) {
                            newWeight = true;
                            PreferencesUtils.storeWeightValue(activity, newValue);
                        }
                    }
                    int selected = imageAdapter.getSelected();
                    caller.onChooseActivityTypeDone(TrackIconUtils.getAllIconValues().get(selected), newWeight);
                }
            }).setTitle(R.string.track_edit_activity_type_hint).setView(view).create();
    alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
        @Override
        public void onShow(DialogInterface dialog) {
            int position = getPosition(activity, category);
            alertDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(position != -1);
            if (position != -1) {
                imageAdapter.setSelected(position);
                imageAdapter.notifyDataSetChanged();
            }
            updateWeightContainer(weightContainer, position);
            weight.setText(weightValue);
            DialogUtils.setDialogTitleDivider(activity, alertDialog);
        }
    });

    gridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            alertDialog.getButton(Dialog.BUTTON_POSITIVE).setEnabled(true);
            imageAdapter.setSelected(position);
            imageAdapter.notifyDataSetChanged();
            updateWeightContainer(weightContainer, position);
        }
    });
    return alertDialog;
}

From source file:com.yahala.ui.Views.EmojiView.java

private void init() {
    setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < Emoji.data.length; i++) {
        GridView gridView = new GridView(getContext());
        gridView.setColumnWidth(OSUtilities.dpf(45.0f));
        gridView.setNumColumns(-1);//from   w w  w.  j ava  2  s. c o  m
        views.add(gridView);

        EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]);
        gridView.setAdapter(localEmojiGridAdapter);
        adapters.add(localEmojiGridAdapter);
    }

    setBackgroundDrawable(
            new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { -14145496, -16777216 }));
    pager = new ViewPager(getContext());
    pager.setAdapter(new EmojiPagesAdapter());
    PagerSlidingTabStripEmoji tabs = new PagerSlidingTabStripEmoji(getContext());
    tabs.setViewPager(pager);
    tabs.setShouldExpand(true);
    tabs.setIndicatorColor(0xff33b5e5);
    tabs.setIndicatorHeight(OSUtilities.dpf(2.0f));
    tabs.setUnderlineHeight(OSUtilities.dpf(2.0f));
    tabs.setUnderlineColor(1711276032);
    tabs.setTabBackground(0);
    LinearLayout localLinearLayout = new LinearLayout(getContext());
    localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    localLinearLayout.addView(tabs,
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    ImageView localImageView = new ImageView(getContext());
    localImageView.setImageResource(R.drawable.ic_emoji_backspace);
    localImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
    localImageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (EmojiView.this.listener != null) {
                EmojiView.this.listener.onBackspace();
            }
        }
    });
    localLinearLayout.addView(localImageView,
            new LinearLayout.LayoutParams(OSUtilities.dpf(61.0f), LayoutParams.MATCH_PARENT));
    recentsWrap = new FrameLayout(getContext());
    recentsWrap.addView(views.get(0));
    TextView localTextView = new TextView(getContext());
    localTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
    localTextView.setTextSize(18.0f);
    localTextView.setTextColor(-7829368);
    localTextView.setGravity(17);
    recentsWrap.addView(localTextView);
    views.get(0).setEmptyView(localTextView);
    addView(localLinearLayout, new LinearLayout.LayoutParams(-1, OSUtilities.dpf(48.0f)));
    addView(pager);
    loadRecents();
    if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
        pager.setCurrentItem(1);
    }
}

From source file:org.mareatlantica.ui.Views.EmojiView.java

private void init() {
    setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < Emoji.data.length; i++) {
        GridView gridView = new GridView(getContext());
        gridView.setColumnWidth(AndroidUtilities.dpf(45.0f));
        gridView.setNumColumns(-1);//from ww  w.  j a  v  a 2 s. c o m
        views.add(gridView);

        EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]);
        gridView.setAdapter(localEmojiGridAdapter);
        adapters.add(localEmojiGridAdapter);
    }

    setBackgroundDrawable(
            new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { -14145496, -16777216 }));
    pager = new ViewPager(getContext());
    pager.setAdapter(new EmojiPagesAdapter());
    PagerSlidingTabStrip tabs = new PagerSlidingTabStrip(getContext());
    tabs.setViewPager(pager);
    tabs.setShouldExpand(true);
    tabs.setIndicatorColor(0xff33b5e5);
    tabs.setIndicatorHeight(AndroidUtilities.dpf(2.0f));
    tabs.setUnderlineHeight(AndroidUtilities.dpf(2.0f));
    tabs.setUnderlineColor(1711276032);
    tabs.setTabBackground(0);
    LinearLayout localLinearLayout = new LinearLayout(getContext());
    localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    localLinearLayout.addView(tabs,
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    ImageView localImageView = new ImageView(getContext());
    localImageView.setImageResource(R.drawable.ic_emoji_backspace);
    localImageView.setScaleType(ImageView.ScaleType.CENTER);
    localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
    localImageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (EmojiView.this.listener != null) {
                EmojiView.this.listener.onBackspace();
            }
        }
    });
    localLinearLayout.addView(localImageView,
            new LinearLayout.LayoutParams(AndroidUtilities.dpf(61.0f), LayoutParams.MATCH_PARENT));
    recentsWrap = new FrameLayout(getContext());
    recentsWrap.addView(views.get(0));
    TextView localTextView = new TextView(getContext());
    localTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
    localTextView.setTextSize(18.0f);
    localTextView.setTextColor(-7829368);
    localTextView.setGravity(17);
    recentsWrap.addView(localTextView);
    views.get(0).setEmptyView(localTextView);
    addView(localLinearLayout, new LinearLayout.LayoutParams(-1, AndroidUtilities.dpf(48.0f)));
    addView(pager);
    loadRecents();
    if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
        pager.setCurrentItem(1);
    }
}

From source file:hoahong.facebook.messenger.ui.EmojiView.java

private void init() {
    setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < Emoji.data.length; i++) {
        GridView gridView = new GridView(getContext());
        if (Utils.isTablet()) {
            gridView.setColumnWidth(Utils.dp(60));
        } else {/*from   w w  w. j  av  a2  s .  c o  m*/
            gridView.setColumnWidth(Utils.dp(45));
        }
        gridView.setNumColumns(-1);
        views.add(gridView);

        EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]);
        gridView.setAdapter(localEmojiGridAdapter);
        adapters.add(localEmojiGridAdapter);
    }

    setBackgroundDrawable(
            new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { -14145496, -16777216 }));
    pager = new ViewPager(getContext());
    pager.setAdapter(new EmojiPagesAdapter());
    PagerSlidingTabStrip tabs = new PagerSlidingTabStrip(getContext());
    tabs.setViewPager(pager);
    tabs.setShouldExpand(true);
    tabs.setIndicatorColor(0xff33b5e5);
    tabs.setIndicatorHeight(Utils.dpf(2.0f));
    tabs.setUnderlineHeight(Utils.dpf(2.0f));
    tabs.setUnderlineColor(0x66000000);
    tabs.setTabBackground(0);
    LinearLayout localLinearLayout = new LinearLayout(getContext());
    localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    localLinearLayout.addView(tabs,
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    ImageView localImageView = new ImageView(getContext());
    localImageView.setImageResource(R.drawable.ic_emoji_backspace);
    localImageView.setScaleType(ImageView.ScaleType.CENTER);
    localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
    localImageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (EmojiView.this.listener != null) {
                EmojiView.this.listener.onBackspace();
            }
        }
    });
    localLinearLayout.addView(localImageView,
            new LinearLayout.LayoutParams(Utils.dp(61), LayoutParams.MATCH_PARENT));
    recentsWrap = new FrameLayout(getContext());
    recentsWrap.addView(views.get(0));
    TextView localTextView = new TextView(getContext());
    localTextView.setText("No recent");
    localTextView.setTextSize(18.0f);
    localTextView.setTextColor(-7829368);
    localTextView.setGravity(17);
    recentsWrap.addView(localTextView);
    views.get(0).setEmptyView(localTextView);
    addView(localLinearLayout, new LinearLayout.LayoutParams(-1, Utils.dpf(48.0f)));
    addView(pager);
    loadRecents();
    if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
        pager.setCurrentItem(1);
    }
}

From source file:me.cpwc.nibblegram.ui.Components.EmojiView.java

private void init() {
    setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < Emoji.data.length; i++) {
        GridView gridView = new GridView(getContext());
        if (AndroidUtilities.isTablet()) {
            gridView.setColumnWidth(AndroidUtilities.dp(60));
        } else {/* w w w . j  av a2  s.c  om*/
            gridView.setColumnWidth(AndroidUtilities.dp(45));
        }
        gridView.setNumColumns(-1);
        views.add(gridView);

        EmojiGridAdapter localEmojiGridAdapter = new EmojiGridAdapter(Emoji.data[i]);
        gridView.setAdapter(localEmojiGridAdapter);
        AndroidUtilities.setListViewEdgeEffectColor(gridView, 0xff999999);
        adapters.add(localEmojiGridAdapter);
    }

    setBackgroundColor(0xff222222);
    pager = new ViewPager(getContext());
    pager.setAdapter(new EmojiPagesAdapter());
    PagerSlidingTabStrip tabs = new PagerSlidingTabStrip(getContext());
    tabs.setViewPager(pager);
    tabs.setShouldExpand(true);
    tabs.setIndicatorColor(0xff33b5e5);
    tabs.setIndicatorHeight(AndroidUtilities.dp(2.0f));
    tabs.setUnderlineHeight(AndroidUtilities.dp(2.0f));
    tabs.setUnderlineColor(0x66000000);
    tabs.setTabBackground(0);
    LinearLayout localLinearLayout = new LinearLayout(getContext());
    localLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
    localLinearLayout.addView(tabs,
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
    ImageView localImageView = new ImageView(getContext());
    localImageView.setImageResource(R.drawable.ic_emoji_backspace);
    localImageView.setScaleType(ImageView.ScaleType.CENTER);
    localImageView.setBackgroundResource(R.drawable.bg_emoji_bs);
    localImageView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            if (EmojiView.this.listener != null) {
                EmojiView.this.listener.onBackspace();
            }
        }
    });
    localLinearLayout.addView(localImageView,
            new LinearLayout.LayoutParams(AndroidUtilities.dp(61), LayoutParams.MATCH_PARENT));
    recentsWrap = new FrameLayout(getContext());
    recentsWrap.addView(views.get(0));
    TextView localTextView = new TextView(getContext());
    localTextView.setText(LocaleController.getString("NoRecent", R.string.NoRecent));
    localTextView.setTextSize(18.0f);
    localTextView.setTextColor(-7829368);
    localTextView.setGravity(17);
    recentsWrap.addView(localTextView);
    views.get(0).setEmptyView(localTextView);
    addView(localLinearLayout, new LinearLayout.LayoutParams(-1, AndroidUtilities.dp(48.0f)));
    addView(pager);
    loadRecents();
    if (Emoji.data[0] == null || Emoji.data[0].length == 0) {
        pager.setCurrentItem(1);
    }
}