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

The following examples show how to use android.widget.GridView#setLayoutParams() . 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: 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 3
Source File: JKCalendar.java    From JKCalendar with Apache License 2.0 6 votes vote down vote up
/**
 * 重新計算GridView的高度
 *
 * @param gridView
 */
public static void setGridViewHeightBasedOnChildren(GridView gridView, int columns) {

    ListAdapter listAdapter = gridView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        return;
    }

    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount() / columns; i++) {
        View listItem = listAdapter.getView(i, null, gridView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = gridView.getLayoutParams();
    params.height = totalHeight + (listAdapter.getCount() - 1);
    gridView.setLayoutParams(params);
    gridView.requestLayout();
}
 
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: GridViewSample.java    From pixate-freestyle-android with Apache License 2.0 6 votes vote down vote up
@Override
public void createViews(Context context, ViewGroup layout) {
    GridView gridView = new GridView(context);
    PixateFreestyle.setStyleClass(gridView, "myGridView");

    gridView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT));

    String[] vals = new String[] { "Apples", "Pears", "Oranges", "Watermelon", "Kumquats",
            "Cherries", "Strawberries", "Kiwi" };

    ListAdapter adapter = new ArrayAdapter<String>(context,
            android.R.layout.simple_list_item_1, vals);
    gridView.setAdapter(adapter);

    layout.addView(gridView);

    addView(gridView);
}
 
Example 6
Source File: ListViewHeight.java    From MissZzzReader with Apache License 2.0 6 votes vote down vote up
/**
 * 日期gridview的高度
 * @param gridView
 * @return
 */
public static int setDateGridViewHeightBasedOnChildren(GridView gridView) {
    ListAdapter listAdapter = gridView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        return 0;
    }
    int totalHeight = 0;
    for (int i = 0; i < (listAdapter.getCount()/7); i++) {
        View listItem = listAdapter.getView(i, null, gridView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }
    ViewGroup.LayoutParams params = gridView.getLayoutParams();
    params.height = totalHeight + (1 * (listAdapter.getCount()/7 - 1));
    gridView.setLayoutParams(params);
    return totalHeight + (1 * (listAdapter.getCount()/7 - 1));
}
 
Example 7
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 8
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 9
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 10
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 11
Source File: GridViewUtil.java    From MVPAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
/**
 * Resizes the gridview.
 * @param gridView
 * @param items count
 * @param columns column number
 */
public static void resizeGridView(GridView gridView, int columns) {
    ListAdapter listAdapter = gridView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        return;
    }

    int totalHeight = 0;
    int items = listAdapter.getCount();
    int rows = 0;

    int maxHeight = 0;

    for(int i = 0; i< listAdapter.getCount(); i++ ){
        View listItem = listAdapter.getView(i, null, gridView);
        listItem.measure(0, 0);
        totalHeight = listItem.getMeasuredHeight();
        if(maxHeight < totalHeight){
            maxHeight = totalHeight;
        }
    }



    float x = 1;
    if( items > columns ){
        x = items/columns;
        rows = (int) (x + 1);
        maxHeight *= rows;
    }

    ViewGroup.LayoutParams params = gridView.getLayoutParams();
    params.height = maxHeight;
    gridView.setLayoutParams(params);

}
 
Example 12
Source File: CalendarFragment.java    From MaterialCalendar with Apache License 2.0 5 votes vote down vote up
private void addGridView() {
        gridView = new GridView(this.getActivity());
        gridView.setNumColumns(7);
        gridView.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
        gridView.setGravity(Gravity.CENTER_VERTICAL);
        gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
        gridView.setHorizontalScrollBarEnabled(false);
        gridView.setVerticalScrollBarEnabled(false);
//        gridView.setVerticalSpacing(1);
//        gridView.setHorizontalSpacing(1);
        gridView.setOnTouchListener(new View.OnTouchListener() {
            // 将gridview中的触摸事件回传给gestureDetector

            public boolean onTouch(View v, MotionEvent event) {
                return gestureDetector.onTouchEvent(event);
            }
        });

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
                // 点击任何一个item,得到这个item的日期(排除点击的是周日到周六(点击不响应))
                int startPosition = calV.getStartPositon();
                int endPosition = calV.getEndPosition();
                if (startPosition <= position + 7 && position <= endPosition - 7) {
                    Day clickDay = calV.getItem(position);
                    Logger.d(clickDay.toString(), 2);
                    setTodayLunarInfo(clickDay);
//                    Toast.makeText(CalendarActivity.this, clickDay.toString(), Toast.LENGTH_SHORT).show();
                }
            }
        });
        gridView.setLayoutParams(new LinearLayout.LayoutParams(AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT));
    }
 
Example 13
Source File: GridViewUtil.java    From RxAndroidBootstrap with Apache License 2.0 5 votes vote down vote up
/**
 * Resizes the gridview.
 * @param gridView
 * @param items count
 * @param columns column number
 */
public static void resizeGridView(GridView gridView, int columns) {
    ListAdapter listAdapter = gridView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        return;
    }

    int totalHeight = 0;
    int items = listAdapter.getCount();
    int rows = 0;

    int maxHeight = 0;

    for(int i = 0; i< listAdapter.getCount(); i++ ){
        View listItem = listAdapter.getView(i, null, gridView);
        listItem.measure(0, 0);
        totalHeight = listItem.getMeasuredHeight();
        if(maxHeight < totalHeight){
            maxHeight = totalHeight;
        }
    }



    float x = 1;
    if( items > columns ){
        x = items/columns;
        rows = (int) (x + 1);
        maxHeight *= rows;
    }

    ViewGroup.LayoutParams params = gridView.getLayoutParams();
    params.height = maxHeight;
    gridView.setLayoutParams(params);

}
 
Example 14
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 15
Source File: ListViewHeight.java    From MissZzzReader with Apache License 2.0 4 votes vote down vote up
/**
 * 计算gridview的高度
 * @param gridView
 */
public static void setGridViewHeightBasedOnChildren(GridView gridView) {
    // 获取GridView对应的Adapter
    ListAdapter listAdapter = gridView.getAdapter();
    if (listAdapter == null) {
        return;
    }
    int rows;
    int columnWidths;
    int columns=0;
    int horizontalBorderHeight = 0;
    int verticalBorderHeight = 0;

    Class<?> clazz=gridView.getClass();
    try {
        //利用反射,取得横向分割线高度
        Field vertical=clazz.getDeclaredField("mVerticalSpacing");
        vertical.setAccessible(true);
        verticalBorderHeight =(Integer)vertical.get(gridView);

        //利用反射,取得纵向分割线高度
        Field horizontalSpacing=clazz.getDeclaredField("mRequestedHorizontalSpacing");
        horizontalSpacing.setAccessible(true);
        horizontalBorderHeight=(Integer)horizontalSpacing.get(gridView);

        //利用反射,取得每行显示的个数
        Field column=clazz.getDeclaredField("mRequestedNumColumns");
        column.setAccessible(true);
        columns=(Integer)column.get(gridView);

        if(columns == -1 || columns == 0){
            Field columnWidth = clazz.getDeclaredField("mRequestedColumnWidth");
            columnWidth.setAccessible(true);
            columnWidths = (Integer)columnWidth.get(gridView);
            int pad = gridView.getPaddingLeft() * 2;
            int width = BaseActivity.width - pad * 2;
            columns = width  / (columnWidths /*+ horizontalBorderHeight*/);
            if(horizontalBorderHeight * (columns - 1) + columnWidths * columns > width){
                columns --;
            }
        }

    } catch (Exception e) {
        // TODO: handle exception
        e.printStackTrace();
    }
    //判断数据总数除以每行个数是否整除。不能整除代表有多余,需要加一行
    if(listAdapter.getCount()%columns > 0){
        rows=listAdapter.getCount()/columns+1;
    }else {
        rows=listAdapter.getCount()/columns;
    }
    int totalHeight = 0;
    for (int i = 0; i < rows; i++) { //只计算每项高度*行数
        View listItem = listAdapter.getView(i, null, gridView);
        listItem.measure(0, 0); // 计算子项View 的宽高
        totalHeight += listItem.getMeasuredHeight(); // 统计所有子项的总高度
    }
    ViewGroup.LayoutParams params = gridView.getLayoutParams();
    params.height = totalHeight  + gridView.getPaddingTop() + + gridView.getPaddingBottom() + verticalBorderHeight * (rows-1);//最后加上分割线总高度
    gridView.setLayoutParams(params);
}
 
Example 16
Source File: ListViewUtils.java    From DevUtils with Apache License 2.0 4 votes vote down vote up
/**
 * 计算 GridView 高度
 * @param gridView  {@link GridView}
 * @param setParams 是否 setLayoutParams
 * @return GridView 高度
 */
public static int calcGridViewHeight(final GridView gridView, final boolean setParams) {
    if (gridView == null) return 0;
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) return 0;
    try {
        // Adapter
        ListAdapter listAdapter = gridView.getAdapter();
        // Item 总条数
        int itemCount = listAdapter.getCount();
        // 没数据则直接跳过
        if (itemCount == 0) return 0;
        // 高度
        int height = 0;
        // 获取一共多少列
        int numColumns = gridView.getNumColumns();
        // 每列之间的间隔 |
        int horizontalSpacing = gridView.getHorizontalSpacing();
        // 每行之间的间隔 -
        int verticalSpacing = gridView.getVerticalSpacing();
        // 获取倍数 ( 行数 )
        int lineNumber = NumberUtils.getMultiple(itemCount, numColumns);
        // 计算总共的宽度 - (GridView 宽度 - 列分割间距 ) / numColumns
        int childWidth = (gridView.getWidth() - (numColumns - 1) * horizontalSpacing) / numColumns;

        // 记录每行最大高度
        int[] rowHeightArrays = new int[lineNumber];
        // 临时高度 - 保存行中最高的列高度
        int tempHeight;
        // 循环每一行绘制每个 Item 并保存 Bitmap
        for (int i = 0; i < lineNumber; i++) {
            // 清空高度
            tempHeight = 0;
            // 循环列数
            for (int j = 0; j < numColumns; j++) {
                // 获取对应的索引
                int position = i * numColumns + j;
                // 如果大于总数据则跳过
                if (position < itemCount) {
                    View childView = listAdapter.getView(position, null, gridView);
                    WidgetUtils.measureView(childView, childWidth);

                    int itemHeight = childView.getMeasuredHeight();
                    // 保留最大高度
                    tempHeight = Math.max(itemHeight, tempHeight);
                }

                // 记录高度并累加
                if (j == numColumns - 1) {
                    height += tempHeight;
                    rowHeightArrays[i] = tempHeight;
                }
            }
        }
        // 追加子项间分隔符占用的高度
        height += (verticalSpacing * (lineNumber - 1));

        // 是否需要设置高度
        if (setParams) {
            ViewGroup.LayoutParams params = gridView.getLayoutParams();
            params.height = height;
            gridView.setLayoutParams(params);
        }
        return height;
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "calcGridViewHeight");
    }
    return 0;
}
 
Example 17
Source File: ChatActivity.java    From weixin with Apache License 2.0 4 votes vote down vote up
/**
 * 设置笑脸被点击后的表情数据
 */
private void setSmilingfaceData() {
	mV_myScrollView = new MyScrollView(this);
	mList_emoji = FaceConversionUtil.getInstace().emojiLists;

	// 添加表情页
	mList_emojiAdapter = new ArrayList<EmojiAdapter>();
	mV_myScrollView.removeAllViews();
	for (int i = 0; i < mList_emoji.size(); i++) {
		//			GridView的一些特殊属性:
		//
		//			1.android:numColumns=”auto_fit”   //GridView的列数设置为自动
		//			2.android:columnWidth=”90dp "       //每列的宽度,也就是Item的宽度
		//			3.android:stretchMode=”columnWidth"//缩放与列宽大小同步
		//			4.android:verticalSpacing=”10dp”          //两行之间的边距
		//			5.android:horizontalSpacing=”10dp”      //两列之间的边距 
		//			6.android:cacheColorHint="#00000000" //去除拖动时默认的黑色背景
		//			7.android:listSelector="#00000000"        //去除选中时的黄色底色
		//			8.android:scrollbars="none"                   //隐藏GridView的滚动条
		//			9.android:fadeScrollbars="true"             //设置为true就可以实现滚动条的自动隐藏和显示
		//			10.android:fastScrollEnabled="true"      //GridView出现快速滚动的按钮(至少滚动4页才会显示)
		//			11.android:fadingEdge="none"                //GridView衰落(褪去)边缘颜色为空,缺省值是vertical。(可以理解为上下边缘的提示色)
		//			12.android:fadingEdgeLength="10dip"   //定义的衰落(褪去)边缘的长度
		//			13.android:stackFromBottom="true"       //设置为true时,你做好的列表就会显示你列表的最下面
		//			14.android:transcriptMode="alwaysScroll" //当你动态添加数据时,列表将自动往下滚动最新的条目可以自动滚动到可视范围内
		//			15.android:drawSelectorOnTop="false"  //点击某条记录不放,颜色会在记录的后面成为背景色,内容的文字可见(缺省为false)
		//			
		GridView view = new GridView(this);
		EmojiAdapter adapter = new EmojiAdapter(this, mList_emoji.get(i));
		view.setAdapter(adapter);
		mList_emojiAdapter.add(adapter);
		view.setOnItemClickListener(this);
		view.setNumColumns(7);
		view.setBackgroundColor(Color.TRANSPARENT);
		//			view.setHorizontalSpacing(1); //两列之间的边距
		//			view.setVerticalSpacing(10);//两行之间的边距
		view.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);//缩放与列宽大小同步
		view.setCacheColorHint(0);//去除拖动时默认的黑色背景
		//						view.setPadding(5, 5, 5, 5);
		view.setSelector(new ColorDrawable(Color.TRANSPARENT));
		LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		view.setLayoutParams(params);
		view.setGravity(Gravity.CENTER);
		mV_myScrollView.addView(view);
	}

	mLl_chat_smilingface_body.removeAllViews();
	mLl_chat_smilingface_body.addView(mV_myScrollView);//将MyScrollView添加到内容显示区

	RadioGroup.LayoutParams params_rb = new RadioGroup.LayoutParams(DensityUtil.dip2px(this, 8), DensityUtil.dip2px(this, 8));
	int marginValue = DensityUtil.dip2px(this, 3);
	params_rb.setMargins(marginValue, 0, marginValue, 0);
	for (int i = 0; i < mV_myScrollView.getChildCount(); i++) {
		RadioButton rbtn = new RadioButton(this);
		rbtn.setButtonDrawable(R.drawable.cgt_selector_chat_radiobtn_bg);
		rbtn.setId(i);
		mRg_chat_smilingface_tab.addView(rbtn, params_rb);
		if (i == 0) {
			rbtn.setChecked(true);
		}
	}
	/**
	 * 监听单选按钮是否被选中,
	 */
	mRg_chat_smilingface_tab.setOnCheckedChangeListener(new OnCheckedChangeListener() {

		@Override
		public void onCheckedChanged(RadioGroup group, int checkedId) {
			current = checkedId;
			mV_myScrollView.moveToDest(checkedId);
		}
	});

	/**
	 * 
	 */
	mV_myScrollView.setChangedListener(new IPageChangedListener() {

		@Override
		public void changedTo(int pageId) {
			current = pageId;
			((RadioButton) mRg_chat_smilingface_tab.getChildAt(pageId)).setChecked(true);
		}
	});
}
 
Example 18
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 19
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 20
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菜单中的控件事件无法响应  
}