GridView setStretchMode - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for GridView setStretchMode method.

This code example shows how to use the following methods: setRecyclerListener, setAdapter, setColumnWidth, setHorizontalSpacing, setStretchMode
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(this.getResources().getIdentifier("test_activity_grid", "layout", "pl.polidea.androidflip3d"));
        final GridView gridView = (GridView) findViewById(this.getResources().getIdentifier("GridView", "id",
                "pl.polidea.androidflip3d")); 
        gridView.setHorizontalSpacing(0);
        final int screenWidth = this.getWindow().getWindowManager().getDefaultDisplay().getWidth();
        final int margin = 10;
        Log.v(TAG, "Screen width = " + screenWidth);
        gridView.setColumnWidth(screenWidth / 3 - margin * 2 / 3);
        gridView.setStretchMode(GridView.NO_STRETCH);
        gridView.setHorizontalSpacing(margin / 2);
        gridView.setVerticalSpacing(margin / 2);
        final TestGridAdapter adapter = new TestGridAdapter(this, screenWidth / 3 - margin);
        gridView.setAdapter(adapter);
        gridView.setRecyclerListener(adapter);
    } 
} 
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setGravity, setHorizontalSpacing, setNumColumns, setStretchMode, setVerticalSpacing
		this.mResources = context.getResources();
		init(); 
	} 
	 
	private void init() { 
		mGridView = new GridView(mContext);
		mGridView.setNumColumns(4);
		mGridView.setHorizontalSpacing(10);
		mGridView.setVerticalSpacing(10);
		mGridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
		mGridView.setGravity(Gravity.CENTER);
		mGridView.setOnItemClickListener(this);
		setAdapterData(menu_name, menu_image);
	} 
 
	private void setAdapterData(String[] menus_name,String[] menus_image) {
		/** 数据源  **/ 
		ArrayList<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();
		/** 添加数据 **/ 
		 for (int i = 0; i < menus_name.length; i++) {            
Full Snippet Info
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setPadding, setVerticalScrollBarEnabled, setAdapter, setGravity, setNumColumns
		 
		Vector <DataIndicator> currentRow = rows.get(position);
		 
		GridView gridView;
        if (convertView == null) {
        	gridView = new GridView(mContext);
             
            gridView.setVerticalScrollBarEnabled(false);          
 
            gridView.setNumColumns(currentRow.size());
            gridView.setPadding(1,1,1,1);
            //gridView.setLayoutParams(new LayoutParams (LayoutParams.FILL_PARENT, 40)); 
            gridView.setGravity(Gravity.CENTER);
            gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
 
        } else { 
        	gridView = (GridView) convertView;
        } 
 
        DataListItemAdapter itemAdapter = new DataListItemAdapter(mContext, currentRow, false);

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setPadding, setFastScrollEnabled, setAdapter, setColumnWidth, setHorizontalSpacing
This code example shows how to use the following methods: setLayoutParams, setPadding, setGravity, setHorizontalSpacing, setNumColumns
This code example shows how to use the following methods: setNumColumns, setStretchMode
      
    /**这个函数就是得到我们要生成的View,这里实际上直接从布局得到,  
    *我们定义的是一个GridView ,一个GridView用于显示一屏的应用程序*/   
    public View makeView() { 
    	 
    	GridView gridView = new GridView(context);
    	gridView.setNumColumns(4);
    	gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    	return gridView ;
        //return mInflater.inflate(R.layout.slidelistview, null);  
    }  
}  
Full Snippet Info
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setLayoutParams, setPadding, setSelector, setGravity, setHorizontalSpacing
		super(context);
 
		mLayout = new LinearLayout(context);
		mLayout.setOrientation(LinearLayout.VERTICAL);
 
		gridView = new GridView(context);
		gridView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.WRAP_CONTENT));
		gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));// 选中的时候为透明色
		gridView.setNumColumns(bodyAdapter.resID.length);
		gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
		gridView.setVerticalSpacing(0);
		gridView.setHorizontalSpacing(0);
		gridView.setPadding(0, 0, 0, 0);
		gridView.setGravity(Gravity.CENTER);
		gridView.setOnItemClickListener(bodyClick);
		//gridView.setBackgroundResource(R.drawable.button); 
		 
		mLayout.addView(gridView);
		// 设置默认项 
		this.setContentView(mLayout);
Full Snippet Info
4
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods: setPadding, setFastScrollEnabled, setAdapter, setColumnWidth, setHorizontalSpacing
This code example shows how to use the following methods: setPadding, setFastScrollEnabled, setAdapter, setColumnWidth, setHorizontalSpacing
This code example shows how to use the following methods: setPadding, setFastScrollEnabled, setAdapter, setColumnWidth, setHorizontalSpacing

Related GridView setStretchMode Questions & Answers:

Other GridView setStretchMode Examples

52:			gridView.setNumColumns(AppConstant.NUM_OF_COLUMNS);
53:			gridView.setColumnWidth(columnWidth);
54:			gridView.setStretchMode(GridView.NO_STRETCH);
55:			gridView.setPadding((int) padding, (int) padding, (int) padding,
56:					(int) padding);

Read More

setStretchMode Method Overview
Control how items are stretched to fill their space.
See Code Examples for other Android GridView Methods: