Java Code Examples for android.widget.GridView#setHorizontalSpacing()

The following examples show how to use android.widget.GridView#setHorizontalSpacing() . 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: EmotionComplateFragment.java    From timecat with Apache License 2.0 7 votes vote down vote up
/**
 * 创建显示表情的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(7);
    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,emotion_map_type);
    gv.setAdapter(adapter);
    //设置全局点击事件
    gv.setOnItemClickListener(GlobalOnItemClickManager.getInstance(getActivity())
            .getOnItemClickListener(emotion_map_type));
    return gv;
}
 
Example 2
Source File: ChatEmotionFragment.java    From chatui with Apache License 2.0 6 votes vote down vote up
/**
 * 创建显示表情的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: MonthViewPagerAdapter.java    From FlexibleCalendar with MIT License 6 votes vote down vote up
@Override
public Object instantiateItem(ViewGroup container, int position) {
    LayoutInflater inflater = LayoutInflater.from(context);
    LinearLayout layout = new LinearLayout(context);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    FlexibleCalendarGridAdapter adapter = dateAdapters.get(position);
    adapter.setOnDateClickListener(onDateCellItemClickListener);
    adapter.setMonthEventFetcher(monthEventFetcher);
    adapter.setCellViewDrawer(cellViewDrawer);

    GridView view = (GridView) inflater.inflate(R.layout.month_grid_layout, null);
    view.setTag(GRID_TAG_PREFIX + position);
    view.setAdapter(adapter);
    view.setVerticalSpacing(gridViewVerticalSpacing);
    view.setHorizontalSpacing(gridViewHorizontalSpacing);

    layout.addView(view);
    container.addView(layout);
    return layout;
}
 
Example 4
Source File: PXGridStyler.java    From pixate-freestyle-android with Apache License 2.0 6 votes vote down vote up
@Override
public void applyStylesWithContext(PXStylerContext stylerContext) {

    GridStyle style = stylerContext.getGridStyle();
    if (style != null) {
        GridView view = (GridView) stylerContext.getStyleable();
        if (style.columnCount != Integer.MIN_VALUE) {
            view.setNumColumns(style.columnCount);
        }
        if (style.columnWidth != Integer.MIN_VALUE) {
            view.setColumnWidth(style.columnWidth);
        }
        if (style.columnGap != Integer.MIN_VALUE) {
            view.setHorizontalSpacing(style.columnGap);
        }
        if (style.rowGap != Integer.MIN_VALUE) {
            view.setVerticalSpacing(style.rowGap);
        }
        if (style.columnStretchMode != Integer.MIN_VALUE) {
            view.setStretchMode(style.columnStretchMode);
        }
    }

    super.applyStylesWithContext(stylerContext);
}
 
Example 5
Source File: ChatEmotionFragment.java    From Socket.io-FLSocketIM-Android with MIT License 5 votes vote down vote up
private GridView createEmotionGridView(final List<String> emotionNames, int gvWidth, int padding, int itemWidth, int gvHeight) {

        GridView gv = new GridView(mContext);
        gv.setNumColumns(8);
        gv.setPadding(padding, padding, padding, padding);
        gv.setHorizontalSpacing(padding);
        gv.setVerticalSpacing(padding*2);

        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(gvWidth, gvHeight);
        gv.setLayoutParams(params);

        EmotionGridViewAdapter adapter = new EmotionGridViewAdapter(mContext, emotionNames, itemWidth);
        gv.setAdapter(adapter);

        gv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                if (clickCallBack == null) {
                    return;
                }
                if (view instanceof ImageView) {
                    clickCallBack.onClickDelete();
                } else {
                    String emotion = emotionNames.get(i);
                    clickCallBack.onClickEmotion(emotion);
                }



            }
        });

        return gv;
    }
 
Example 6
Source File: AvatarGridView.java    From Android with MIT License 5 votes vote down vote up
public AvatarGridView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    View view = View.inflate(context, R.layout.avater_gridview, this);
    avatarRimg = (RoundedImageView)view.findViewById(R.id.avatar_rimg);
    gridRela = (RelativeLayout)view.findViewById(R.id.grid_rela);
    gridView = (GridView) view.findViewById(R.id.grid_view);
    gridView.setHorizontalSpacing(DEFAULT_SPACING);
    gridView.setVerticalSpacing(DEFAULT_SPACING);
    adapter = new Adapter();
    gridView.setAdapter(adapter);
}
 
Example 7
Source File: TransferFriendPresenter.java    From Android with MIT License 5 votes vote down vote up
@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 8
Source File: WeekCalendar.java    From WeekCalendar with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化日期
 */
private GridView addDayView() {
    LayoutParams params = new LayoutParams(
            AbsListView.LayoutParams.FILL_PARENT, AbsListView.LayoutParams.WRAP_CONTENT);
    final GridView gridView = new GridView(context);
    gridView.setNumColumns(7);
    gridView.setGravity(Gravity.CENTER_VERTICAL);
    gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
    gridView.setVerticalSpacing(1);
    gridView.setHorizontalSpacing(1);
    gridView.setLayoutParams(params);
    return gridView;
}
 
Example 9
Source File: MyColorPicker.java    From Ruisi with Apache License 2.0 5 votes vote down vote up
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 10
Source File: AlAttachmentView.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void createView() {
    removeAllViews();
    GridView gridView = new GridView(getContext());
    LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    gridView.setLayoutParams(params);
    gridView.setNumColumns(3);
    gridView.setHorizontalSpacing(1);
    gridView.setVerticalSpacing(1);
    gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    prepareAttachmentData(gridView);
    gridView.setOnItemClickListener(this);

    addView(gridView);
}
 
Example 11
Source File: GridViewStyler.java    From dynamico with Apache License 2.0 4 votes vote down vote up
@Override
public View style(View view, JSONObject attributes) throws Exception {
    super.style(view, attributes);

    GridView gridView = (GridView) view;

    if(attributes.has("numColumns")) {
        gridView.setNumColumns(attributes.getInt("numColumns"));
    }

    if(attributes.has("selection")) {
        gridView.setSelection(attributes.getInt("selection"));
    }

    if(attributes.has("horizontalSpacing")) {
        gridView.setHorizontalSpacing(Display.unitToPx(attributes.getString("horizontalSpacing"), context));
    }

    if(attributes.has("verticalSpacing")) {
        gridView.setVerticalSpacing(Display.unitToPx(attributes.getString("verticalSpacing"), context));
    }

    if(attributes.has("columnWidth")) {
        gridView.setColumnWidth(Display.unitToPx(attributes.getString("columnWidth"), context));
    }

    if(attributes.has("stretchMode")) {
        String mode = attributes.getString("stretchMode");

        if(mode.equalsIgnoreCase("no_stretch")) {
            gridView.setStretchMode(NO_STRETCH);
        }else if(mode.equalsIgnoreCase("stretch_spacing")) {
            gridView.setStretchMode(STRETCH_SPACING);
        }else if(mode.equalsIgnoreCase("stretch_column_width")) {
            gridView.setStretchMode(STRETCH_COLUMN_WIDTH);
        }else if(mode.equalsIgnoreCase("stretch_spacing_uniform")) {
            gridView.setStretchMode(STRETCH_SPACING_UNIFORM);
        }
    }

    if(attributes.has("gravity")) {
        String gravity = attributes.getString("gravity");

        if(gravity.equalsIgnoreCase("start")) {
            gridView.setGravity(Gravity.START);
        }else if(gravity.equalsIgnoreCase("top")) {
            gridView.setGravity(Gravity.TOP);
        }else if(gravity.equalsIgnoreCase("end")) {
            gridView.setGravity(Gravity.END);
        }else if(gravity.equalsIgnoreCase("bottom")) {
            gridView.setGravity(Gravity.BOTTOM);
        }else if(gravity.equalsIgnoreCase("center")) {
            gridView.setGravity(Gravity.CENTER);
        }else if(gravity.equalsIgnoreCase("center_horizontal")) {
            gridView.setGravity(Gravity.CENTER_HORIZONTAL);
        }else if(gravity.equalsIgnoreCase("center_vertical")) {
            gridView.setGravity(Gravity.CENTER_VERTICAL);
        }
    }

    return gridView;
}
 
Example 12
Source File: FlexibleCalendarView.java    From FlexibleCalendar with MIT License 4 votes vote down vote up
private void init(AttributeSet attrs) {
    setAttributes(attrs);
    setOrientation(VERTICAL);

    //initialize the default calendar view
    calendarView = new DefaultCalendarView();

    //create week view header
    weekDisplayView = new GridView(context);
    weekDisplayView.setLayoutParams(
            new GridView.LayoutParams(GridView.LayoutParams.MATCH_PARENT, GridView.LayoutParams.WRAP_CONTENT));
    weekDisplayView.setNumColumns(7);
    weekDisplayView.setHorizontalSpacing(weekdayHorizontalSpacing);
    weekDisplayView.setVerticalSpacing(weekdayVerticalSpacing);
    weekDisplayView.setColumnWidth(GridView.STRETCH_COLUMN_WIDTH);
    weekDisplayView.setBackgroundResource(weekViewBackground);
    weekdayDisplayAdapter = new WeekdayNameDisplayAdapter(getContext(),
            android.R.layout.simple_list_item_1, startDayOfTheWeek);

    //setting default week cell view
    weekdayDisplayAdapter.setCellView(new WeekdayCellViewImpl(calendarView));

    weekDisplayView.setAdapter(weekdayDisplayAdapter);
    this.addView(weekDisplayView);

    //setup month view
    monthViewPager = new MonthViewPager(context);
    monthViewPager.setBackgroundResource(monthViewBackground);
    monthViewPager.setNumOfRows(showDatesOutsideMonth ? 6 : FlexibleCalendarHelper.getNumOfRowsForTheMonth(displayYear, displayMonth, startDayOfTheWeek));
    monthViewPagerAdapter = new MonthViewPagerAdapter(context, displayYear, displayMonth, this,
            showDatesOutsideMonth, decorateDatesOutsideMonth, startDayOfTheWeek, disableAutoDateSelection);
    monthViewPagerAdapter.setMonthEventFetcher(this);
    monthViewPagerAdapter.setSpacing(monthDayHorizontalSpacing, monthDayVerticalSpacing);

    //set the default cell view
    monthViewPagerAdapter.setCellViewDrawer(new DateCellViewImpl(calendarView));

    monthInfPagerAdapter = new InfinitePagerAdapter(monthViewPagerAdapter);
    //Initializing with the offset value
    lastPosition = monthInfPagerAdapter.getRealCount() * 100;
    monthViewPager.setAdapter(monthInfPagerAdapter);
    monthViewPager.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT, 1f));
    monthViewPager.addOnPageChangeListener(new MonthChangeListener());

    //initialize with the current selected item
    selectedDateItem = new SelectedDateItem(displayYear, displayMonth, startDisplayDay);
    monthViewPagerAdapter.setSelectedItem(selectedDateItem);

    this.addView(monthViewPager);
}
 
Example 13
Source File: ExtendedCalendarView.java    From ExtendedCalendarView with Apache License 2.0 4 votes vote down vote up
private void init(){
	cal = Calendar.getInstance();
	base = new RelativeLayout(context);
	base.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
	base.setMinimumHeight(50);
	
	base.setId(4);
	
	LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
	params.leftMargin = 16;
	params.topMargin = 50;
	params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
	params.addRule(RelativeLayout.CENTER_VERTICAL);
	prev = new ImageView(context);
	prev.setId(1);
	prev.setLayoutParams(params);
	prev.setImageResource(R.drawable.navigation_previous_item);
	prev.setOnClickListener(this);
	base.addView(prev);
	
	params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
	params.addRule(RelativeLayout.CENTER_HORIZONTAL);
	params.addRule(RelativeLayout.CENTER_VERTICAL);
	month = new TextView(context);
	month.setId(2);
	month.setLayoutParams(params);
	month.setTextAppearance(context, android.R.attr.textAppearanceLarge);
	month.setText(cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault())+" "+cal.get(Calendar.YEAR));
	month.setTextSize(25);
	
	base.addView(month);
	
	params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
	params.rightMargin = 16;
	params.topMargin = 50;
	params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
	params.addRule(RelativeLayout.CENTER_VERTICAL);
	next = new ImageView(context);
	next.setImageResource(R.drawable.navigation_next_item);
	next.setLayoutParams(params);
	next.setId(3);
	next.setOnClickListener(this);
	
	base.addView(next);
	
	addView(base);
	
	params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
	params.bottomMargin = 20;
	params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
	params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
	params.addRule(RelativeLayout.BELOW, base.getId());
	
	calendar = new GridView(context);
	calendar.setLayoutParams(params);
	calendar.setVerticalSpacing(4);
	calendar.setHorizontalSpacing(4);
	calendar.setNumColumns(7);
	calendar.setChoiceMode(GridView.CHOICE_MODE_SINGLE);
	calendar.setDrawSelectorOnTop(true);
	
	mAdapter = new CalendarAdapter(context,cal);
	calendar.setAdapter(mAdapter);
	calendar.setOnTouchListener(new OnTouchListener() {
		
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return calendarGesture.onTouchEvent(event);
        }
    });
	
	addView(calendar);
}
 
Example 14
Source File: TabMenu.java    From coolreader with MIT License 4 votes vote down vote up
public TabMenu(Context context,OnItemClickListener titleClick,OnItemClickListener bodyClick,  
		MenuTitleAdapter titleAdapter,int colorBgTabMenu,int aniTabMenu)
{  
    super(context);  
      
    mLayout = new LinearLayout(context);  
    mLayout.setOrientation(LinearLayout.VERTICAL);  
    //标题选项栏  
    gvTitle = new GridView(context);  
    gvTitle.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));  
    gvTitle.setNumColumns(titleAdapter.getCount());  
    gvTitle.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);  
    gvTitle.setVerticalSpacing(1);  
    gvTitle.setHorizontalSpacing(1);  
    gvTitle.setGravity(Gravity.CENTER);  
    gvTitle.setOnItemClickListener(titleClick);  
    gvTitle.setAdapter(titleAdapter);  
    gvTitle.setSelector(new ColorDrawable(Color.TRANSPARENT));//选中的时候为透明色  
    this.titleAdapter=titleAdapter;  
    //子选项栏  
    gvBody = new GridView(context);  
    gvBody.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));  
    gvBody.setSelector(new ColorDrawable(Color.TRANSPARENT));//选中的时候为透明色  
    gvBody.setNumColumns(4);  
    gvBody.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);  
    gvBody.setVerticalSpacing(10);  
    gvBody.setHorizontalSpacing(10);  
    gvBody.setPadding(5, 5, 5, 5);  
    gvBody.setGravity(Gravity.CENTER);  
    gvBody.setOnItemClickListener(bodyClick);  
    mLayout.addView(gvTitle);  
    mLayout.addView(gvBody);  
      
    //设置默认项  
    this.setContentView(mLayout);  
    this.setWidth(LayoutParams.FILL_PARENT);  
    this.setHeight(LayoutParams.WRAP_CONTENT);  
    this.setBackgroundDrawable(new ColorDrawable(colorBgTabMenu));// 设置TabMenu菜单背景  
    this.setAnimationStyle(aniTabMenu);  
    this.setFocusable(true);// menu菜单获得焦点 如果没有获得焦点menu菜单中的控件事件无法响应  
}