Java Code Examples for android.widget.GridView#setNumColumns()
The following examples show how to use
android.widget.GridView#setNumColumns() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseSharePlatformSelector.java From BiliShare with Apache License 2.0 | 6 votes |
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 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; }
Example 2
Source File: ChatEmotionFragment.java From chatui with Apache License 2.0 | 6 votes |
/** * 创建显示表情的GridView */ private GridView createEmotionGridView(List<String> emotionNames, int gvWidth, int padding, int itemWidth, int gvHeight) { // 创建GridView GridView gv = new GridView(getActivity()); //设置点击背景透明 gv.setSelector(android.R.color.transparent); //设置7列 gv.setNumColumns(8); gv.setPadding(padding, padding, padding, padding); gv.setHorizontalSpacing(padding); gv.setVerticalSpacing(padding * 2); //设置GridView的宽高 ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(gvWidth, gvHeight); gv.setLayoutParams(params); // 给GridView设置表情图片 EmotionGridViewAdapter adapter = new EmotionGridViewAdapter(getActivity(), emotionNames, itemWidth); gv.setAdapter(adapter); //设置全局点击事件 gv.setOnItemClickListener(GlobalOnItemClickManagerUtils.getInstance(getActivity()).getOnItemClickListener()); return gv; }
Example 3
Source File: ColorPreference.java From KAM with GNU General Public License v3.0 | 6 votes |
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { LayoutInflater layoutInflater = LayoutInflater.from(getActivity()); View rootView = layoutInflater.inflate(R.layout.dash_dialog_colors, null); mColorGrid = (GridView) rootView.findViewById(R.id.color_grid); mColorGrid.setNumColumns(mPreference.mNumColumns); mColorGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> listView, View view, int position, long itemId) { mPreference.setValue(mAdapter.getItem(position)); selector.onColorSelected(mAdapter.getItem(position)); dismiss(); } }); tryBindLists(); return new AlertDialog.Builder(getActivity()) .setView(rootView) .create(); }
Example 4
Source File: EmoticonGridFragment.java From EmoticonGIFKeyboard with Apache License 2.0 | 6 votes |
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); ViewFlipper mainViewFlipper = view.findViewById(R.id.recent_emoticon_flipper); List<Emoticon> emoticonList = getEmoticonsList(getArguments().getInt(ARG_CATEGORY_ID, -1)); if (emoticonList.isEmpty()) { mainViewFlipper.setDisplayedChild(1); } else { mainViewFlipper.setDisplayedChild(0); GridView emoticonGrid = view.findViewById(R.id.emoticon_list_grid); emoticonGrid.setNumColumns(getResources().getInteger(R.integer.emoticon_recycler_view_span_size)); emoticonGrid.setOnItemClickListener(this); //Bind the adapter //noinspection WrongConstant EmoticonGridAdapter emoticonGridAdapter = new EmoticonGridAdapter(getActivity(), mEmoticonProvider, emoticonList); emoticonGrid.setAdapter(emoticonGridAdapter); } }
Example 5
Source File: FourQuarterQuizView.java From android-topeka with Apache License 2.0 | 6 votes |
@Override protected View createQuizContentView() { mAnswerView = new GridView(getContext()); mAnswerView.setSelector(R.drawable.selector_button); mAnswerView.setNumColumns(2); mAnswerView.setAdapter(new OptionsQuizAdapter(getQuiz().getOptions(), R.layout.item_answer)); mAnswerView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { allowAnswer(); mAnswered = position; } }); return mAnswerView; }
Example 6
Source File: MainActivity.java From snazzymaps-browser with Apache License 2.0 | 6 votes |
/** * Sets up the progress dialog, and either restores previously retrieved * styles (eg if the screen orientation changes), or loads some styles if * the app is first starting. */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mGridView = (GridView) findViewById(R.id.grid); // Dynamically set the number of GridView columns, based on orientation. int cols = (int) ((float) getWindowManager().getDefaultDisplay().getWidth() / (float) 500); mGridView.setNumColumns(cols); mProgress = new ProgressDialog(this); mProgress.setMessage(getString(R.string.loading)); if (savedInstanceState != null) { mStylesJson = savedInstanceState.getString(STYLES_JSON); populateGrid(); } else { onQueryTextSubmit(getString(R.string.default_search)); } }
Example 7
Source File: CalendarView.java From calendar with Apache License 2.0 | 6 votes |
private void initWeekGridView(Context context) { String[] from = new String[]{"week"}; int[] to = new int[]{R.id.tvWeekDay}; String[] strings = new String[]{ "日", "一", "二", "三", "四", "五", "六" }; List<Map<String, String>> weeks = new ArrayList<>(); for (String string : strings) { Map<String, String> map = new HashMap<>(); map.put(from[0], string); weeks.add(map); } ListAdapter adapter = new SimpleAdapter(context, weeks, R.layout.layout_week_view, from, to); GridView weekView = findViewById(R.id.weekView); weekView.setNumColumns(adapter.getCount()); weekView.setAdapter(adapter); weekView.setSelector(new ColorDrawable(Color.TRANSPARENT)); }
Example 8
Source File: YayaEmoGridView.java From sctalk with Apache License 2.0 | 6 votes |
private GridView getViewPagerItem(final int index) { GridView gridView = new GridView(_context); gridView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)); gridView.setNumColumns(4); gridView.setVerticalScrollBarEnabled(false); gridView.setHorizontalScrollBarEnabled(false); gridView.setPadding(8, 8, 8, 0); gridView.setVerticalSpacing(20); gridView.setSelector(new ColorDrawable(Color.TRANSPARENT)); gridView.setAdapter(new YayaEmoGridViewAdapter(_context, getGridViewData(index))); gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { int start = index * SysConstant.yayaPageSize; onEmoGridViewItemClick.onItemClick(position + start, index); } }); return gridView; }
Example 9
Source File: FangshiActivity.java From MyBlogDemo with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_fangshi); recyclerView = (RecyclerView) findViewById(R.id.rv); LinearLayoutManager manager = new LinearLayoutManager(this); manager.setOrientation(LinearLayoutManager.VERTICAL); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(manager); GridLayoutManager manager1 = new GridLayoutManager(this, 3); GridView gridView = new GridView(this); gridView.setNumColumns(3); recyclerView.setItemAnimator(new DefaultItemAnimator()); adapter = new FangshiAdapter(); recyclerView.setAdapter(adapter); //初始化一个TouchHelperCallback TouchHelperCallback callback = new TouchHelperCallback(); //添加一个回调 callback.setItemTouchCallBack(adapter); //初始化一个ItemTouchHelper ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback); //关联相关的RecycleView itemTouchHelper.attachToRecyclerView(recyclerView); initData(); }
Example 10
Source File: IndexPageAdapter.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
private View getLinkView(int position, View convertView) { if (convertView == null) { convertView = View.inflate(context, R.layout.item_home_link, null); } GridView gridView = ViewHolder.get(convertView, R.id.gridView); gridView.setNumColumns(3); gridView.setColumnWidth(screenWidth / 3); gridView.setAdapter(new LinkAdapter(context, homeConfigJson.getVariables().getMyHome().getFunc().getLink())); return convertView; }
Example 11
Source File: TypeRecommendIndexPageAdapter.java From BigApp_Discuz_Android with Apache License 2.0 | 5 votes |
private View getLinkView(int position, View convertView) { if (convertView == null) { convertView = View.inflate(context, R.layout.item_home_link, null); } GridView gridView = ViewHolder.get(convertView, R.id.gridView); gridView.setNumColumns(3); gridView.setColumnWidth(screenWidth / 3); gridView.setAdapter(new LinkAdapter(context, (ArrayList<HomeConfigItem>) getItem(position))); return convertView; }
Example 12
Source File: MyColorPicker.java From Ruisi with Apache License 2.0 | 5 votes |
private void init() { String[] colors = mContext.getResources().getStringArray(R.array.color_list); for (int i = 0; i < colors.length; i++) { if (colorDatas == null) { colorDatas = new String[colors.length][2]; } colorDatas[i][0] = colors[i].split(",")[0]; colorDatas[i][1] = colors[i].split(",")[1]; } gridView = new GridView(mContext); gridView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); gridView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.white)); gridView.setNumColumns(8); gridView.setPadding(DimenUtils.dip2px(mContext, 8), DimenUtils.dip2px(mContext, 12), DimenUtils.dip2px(mContext, 8), DimenUtils.dip2px(mContext, 12)); gridView.setGravity(Gravity.CENTER); gridView.setHorizontalSpacing(DimenUtils.dip2px(mContext, 4)); gridView.setVerticalSpacing(DimenUtils.dip2px(mContext, 12)); gridView.setOnItemClickListener(this); setWidth(ViewGroup.LayoutParams.WRAP_CONTENT); setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); setBackgroundDrawable(ContextCompat.getDrawable(mContext, R.drawable.rec_solid_primary_bg)); setFocusable(true); setContentView(gridView); adapter = new MyAdapter(); gridView.setAdapter(adapter); }
Example 13
Source File: TransferFriendPresenter.java From Android with MIT License | 5 votes |
@Override public void horizontal_layout(GridView gridView) { int spacingH = SystemUtil.dipToPx(10); int itemWidth = SystemUtil.dipToPx(45); int size = list.size() + 1; int allWidth = ((spacingH + itemWidth) * size); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( allWidth, LinearLayout.LayoutParams.FILL_PARENT); gridView.setLayoutParams(params); gridView.setColumnWidth(itemWidth); gridView.setHorizontalSpacing(spacingH); gridView.setStretchMode(GridView.NO_STRETCH); gridView.setNumColumns(size); }
Example 14
Source File: GridViewFragment.java From AndroidStarterKit with MIT License | 5 votes |
@Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_gridview_main, null); final int colSize = 3; final int columnWidth = getScreenWidth() / colSize; GridView gridView = (GridView) view.findViewById(R.id.grid_view); gridView.setNumColumns(colSize); gridView.setColumnWidth(columnWidth); gridView.setAdapter(new GridViewAdapter(getActivity(), platforms, columnWidth)); return view; }
Example 15
Source File: ColorfulGridActivity.java From Painter with MIT License | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_colorful_grid); GridView gridView = (GridView) findViewById(R.id.gridView); gridView.setAdapter(new ColorfulGridAdapter()); Drawable drawable = getResources().getDrawable(R.drawable.ic_action_sun); int numThatFit = (int) ((float)getResources().getDisplayMetrics().widthPixels/(float)drawable.getIntrinsicWidth()); gridView.setNumColumns(numThatFit); }
Example 16
Source File: WrapGridViewItemActivity.java From Gloading with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); GridView gridView = new GridView(this); gridView.setNumColumns(2); setContentView(gridView); DisplayMetrics dm = getResources().getDisplayMetrics(); size = dm.widthPixels >> 1; gridView.setAdapter(new MyAdapter(initData())); }
Example 17
Source File: EmojiView.java From Yahala-Messenger with MIT License | 4 votes |
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); 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); } }
Example 18
Source File: EntitySelectActivity.java From commcare-android with Apache License 2.0 | 4 votes |
private void setupUI(boolean isOrientationChange) { if (this.getString(R.string.panes).equals("two") && !mNoDetailMode) { if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { setupLandscapeDualPaneView(); } else { setContentView(R.layout.entity_select_layout); restoreExistingSelection(isOrientationChange); } } else { setContentView(R.layout.entity_select_layout); } AdapterView visibleView; GridView gridView = this.findViewById(R.id.screen_entity_select_grid); ListView listView = this.findViewById(R.id.screen_entity_select_list); if (shortSelect.shouldBeLaidOutInGrid()) { visibleView = gridView; gridView.setVisibility(View.VISIBLE); gridView.setNumColumns(shortSelect.getNumEntitiesToDisplayPerRow()); listView.setVisibility(View.GONE); } else { visibleView = listView; listView.setVisibility(View.VISIBLE); gridView.setVisibility(View.GONE); EntitySelectViewSetup.setupDivider(this, listView, shortSelect.usesEntityTileView()); } RxAdapterView.itemClickEvents(visibleView) .subscribeOn(AndroidSchedulers.mainThread()) .throttleFirst(CLICK_DEBOUNCE_TIME, TimeUnit.MILLISECONDS) .subscribe((Consumer<AdapterViewItemClickEvent>)clickEvent -> onEntitySelected(clickEvent.position())); header = findViewById(R.id.entity_select_header); entitySelectSearchUI = new EntitySelectSearchUI(this); restoreLastQueryString(); persistAdapterState(visibleView); setUpCalloutClickListener(); entitySelectSearchUI.setupPreHoneycombFooter(barcodeScanOnClickListener, this.customCallout); setupMapNav(); AdMobManager.requestBannerAdForView(this, findViewById(R.id.ad_container), AdLocation.EntitySelect); }
Example 19
Source File: PictureElement.java From sana.mobile with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * {@inheritDoc} */ @Override protected View createView(Context c) { imageGrid = new GridView(c); Log.i(TAG, "Looking up for encounter: " + getProcedure().getInstanceUri()); String procedureId = getProcedure().getInstanceUri().getLastPathSegment(); Log.w(TAG, "PictureELement: Encounter id " + procedureId); String whereStr; if (!UUIDUtil.isValid(procedureId)) whereStr = ImageSQLFormat.ENCOUNTER_ID + " = ? AND " + ImageSQLFormat.ELEMENT_ID + " = ? AND " + ImageSQLFormat.FILE_VALID + " = ?"; else whereStr = ImageSQLFormat.ENCOUNTER_ID + " = '?' AND " + ImageSQLFormat.ELEMENT_ID + " = ? AND " + ImageSQLFormat.FILE_VALID + " = ?"; Cursor cursor = c.getContentResolver().query( SanaDB.ImageSQLFormat.CONTENT_URI, new String[]{ImageSQLFormat._ID}, whereStr, new String[]{procedureId, id, "1"}, null); // HAXMODE -- if we don't do this we leak the Cursor if (c instanceof Activity) { ((Activity) c).startManagingCursor(cursor); } imageAdapter = new ScalingImageAdapter(c, cursor, THUMBNAIL_SCALE_FACTOR); imageGrid.setAdapter(imageAdapter); imageGrid.setNumColumns(3); imageGrid.setVerticalSpacing(5); imageGrid.setPadding(5, 0, 0, 0); imageGrid.setOnItemClickListener(this); imageGrid.setOnItemLongClickListener(this); //imageGrid.setTranscriptMode(imageGrid.TRANSCRIPT_MODE_ALWAYS_SCROLL); cameraButton = new Button(c); cameraButton.setText(R.string.btn_add_photo); cameraButton.setOnClickListener(this); imageReview = new ImagePreviewDialog(c); LinearLayout picContainer = new LinearLayout(c); picContainer.setOrientation(LinearLayout.VERTICAL); if (question == null) { question = c.getString(R.string.question_standard_picture_element); } //Set question TextView tv = new TextView(c); tv.setText(String.format("%s: %s", id, question)); tv.setGravity(Gravity.CENTER); tv.setTextAppearance(c, android.R.style.TextAppearance_Medium); //Add to layout picContainer.addView(tv, new LinearLayout.LayoutParams(-1, -1, 0.1f)); //picContainer.addView(imageView, new LinearLayout.LayoutParams(-1,-1,0.1f)); //Add button picContainer.addView(cameraButton, new LinearLayout.LayoutParams(-1, -1, 0.1f)); picContainer.addView(imageGrid, new LinearLayout.LayoutParams(-1, 210)); //LayoutParams(-1,-1,0.8f)); picContainer.setWeightSum(1.0f); return picContainer; }
Example 20
Source File: PaletteFragment.java From color-picker with Apache License 2.0 | 4 votes |
@Override public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); /* * TODO: build the layout programmatically to get rid of the resources, so we can distribute this in a single jar */ final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.dmfs_colorpickerdialog_palette_grid, container, false); final GridView gridview = (GridView) rootView.findViewById(android.R.id.content); mAdapter = new PaletteGridAdapter(getActivity(), mPalette); gridview.setAdapter(mAdapter); gridview.setOnItemClickListener(this); gridview.setNumColumns(mAdapter.getNumColumns()); /* * Adjust the layout of the gridview to a square. * * Inspired by Bill Lahti, see http://blahti.wordpress.com/2012/07/23/three-variations-of-image-squares/ */ gridview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @SuppressLint("NewApi") public void onGlobalLayout() { int parentHeight = rootView.getHeight() - rootView.getPaddingTop() - rootView.getPaddingBottom(); int parentWidth = rootView.getWidth() - rootView.getPaddingLeft() - rootView.getPaddingRight(); int gridWidth = Math.min(parentWidth, parentHeight); int columnSpacing; if (android.os.Build.VERSION.SDK_INT >= 16) { columnSpacing = gridview.getHorizontalSpacing() * (mAdapter.getNumColumns() - 1); } else { /* * TODO: getHorizontalSpacing() has been introduced in SDK level 16. We need to find a way to get get the actual spacing. Until then we use * a hard coded value of 8 dip. * * One way would be to use a dimension in the layout. That would allow us to resolve the dimension here. However, that would be one step * away from a library without resource dependencies. Maybe there is an Android dimension resource with a reasonable value? */ DisplayMetrics metrics = inflater.getContext().getResources().getDisplayMetrics(); columnSpacing = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, metrics) * (mAdapter.getNumColumns() - 1); } // width of a single column int columnWidth = (gridWidth - columnSpacing) / mAdapter.getNumColumns(); // estimated width of the grid int actualGridWidth = mAdapter.getNumColumns() * columnWidth + columnSpacing; // add padding to center the grid if we don't use the entire space due to rounding errors if (actualGridWidth < gridWidth - 1) { int padding = (gridWidth - actualGridWidth) / 2; if (padding > 0) { gridview.setPadding(padding, padding, padding, padding); } } else { // no padding needed gridview.setPadding(0, 0, 0, 0); } // set the column width gridview.setColumnWidth(columnWidth); android.view.ViewGroup.LayoutParams params = gridview.getLayoutParams(); if (params == null || params.height != gridWidth) // avoid unnecessary updates { LayoutParams lparams = new LinearLayout.LayoutParams(gridWidth, gridWidth); gridview.setLayoutParams(lparams); } } }); return rootView; }