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

The following examples show how to use android.widget.GridView#setVerticalSpacing() . 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: 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 4
Source File: EmoGridView.java    From sctalk with Apache License 2.0 6 votes vote down vote up
private GridView getViewPagerItem(final int index) {
    GridView gridView = new GridView(_context);
    gridView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT));
    gridView.setNumColumns(7);
    gridView.setVerticalScrollBarEnabled(false);
    gridView.setHorizontalScrollBarEnabled(false);
    gridView.setPadding(8, 8, 8, 0);
    gridView.setVerticalSpacing(CommonUtil.getElementSzie(_context) / 2
            + CommonUtil.getElementSzie(_context) / 3);
    // gridView.setVerticalSpacing(30);
    gridView.setBackgroundColor(Color.TRANSPARENT);
    gridView.setAdapter(new EmoGridViewAdapter(_context,
            getGridViewData(index)));
    gridView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            int start = index * (SysConstant.pageSize - 1);
            onEmoGridViewItemClick.onItemClick(position + start, index);
        }
    });
    return gridView;
}
 
Example 5
Source File: YayaEmoGridView.java    From sctalk with Apache License 2.0 6 votes vote down vote up
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 6
Source File: MainViewHelper.java    From palmsuda with Apache License 2.0 6 votes vote down vote up
private GridView createGridView(List<ModuleItem> items) {
	GridView gView = (GridView) mInflater.inflate(R.layout.main_gridview,
			null);
	gView.setVerticalSpacing(vspace);
	gView.setPadding(0, vspace / 2, 0, 0);
	GdvAdapter adapter = new GdvAdapter(mActivity,
			mActivity.getImageWorker(), gView);
	adapter.setData(items);
	gView.setAdapter(adapter);
	gView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			ModuleItem item = (ModuleItem) arg0.getAdapter().getItem(arg2);
			mActivity.gridViewClick(mAItem, item);
		}
	});
	return gView;
}
 
Example 7
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 8
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 9
Source File: AlbumActivity.java    From socialauth-android with MIT License 5 votes vote down vote up
/**
 * collection of grid properties
 */
@SuppressWarnings("static-access")
public void getGridProperties(GridView view) {
	view.setNumColumns(3);
	view.setVerticalSpacing(5);
	view.setScrollBarStyle(view.SCROLLBARS_OUTSIDE_OVERLAY);
	view.setScrollingCacheEnabled(false);
	view.setGravity(Gravity.TOP);
	view.setSelector(new ColorDrawable(Color.parseColor("#00000000")));
	view.setClipChildren(true);
	view.setPadding(5, 5, 5, 5);
}
 
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: 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 12
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 13
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 14
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 15
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 16
Source File: PictureElement.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * {@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 17
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菜单中的控件事件无法响应  
}
 
Example 18
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;
}