Java Code Examples for android.widget.RadioGroup#LayoutParams

The following examples show how to use android.widget.RadioGroup#LayoutParams . 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: BannerView.java    From MvpRoute with Apache License 2.0 6 votes vote down vote up
@NonNull
private RadioButton initData(int length, int i, Object imagepath) {
	initImageView(i, imagepath);
	RadioButton radioButton = new RadioButton(context);
	if (selectTab != 0) {
		radioButton.setBackgroundResource(selectTab);
		radioButton.setButtonDrawable(context.getResources().getDrawable(android.R.color.transparent));
	}
	RadioGroup.LayoutParams buttonParams = new RadioGroup.LayoutParams(tabWidth, tabHeight);
	if (i != length - 1) {
		buttonParams.setMargins(0, 0, tabMargin, 0);
	}
	radioButton.setLayoutParams(buttonParams);
	radioButton.setId(i);
	if (i == 0) radioButton.setChecked(true);
	return radioButton;
}
 
Example 2
Source File: WizardFragment.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
private void createRadioButtons() {
  // set button dimension
  int buttonSize = AptoideUtils.ScreenU.getPixelsForDip(10, getResources());
  ViewGroup.LayoutParams buttonLayoutParams = new RadioGroup.LayoutParams(buttonSize, buttonSize);

  // set button margin
  int buttonMargin = AptoideUtils.ScreenU.getPixelsForDip(2, getResources());
  ViewGroup.MarginLayoutParams marginLayoutParams =
      (ViewGroup.MarginLayoutParams) buttonLayoutParams;
  marginLayoutParams.setMargins(buttonMargin, buttonMargin, buttonMargin, buttonMargin);

  final int pages = viewPagerAdapter.getCount();
  wizardButtons = new ArrayList<>(pages);
  Context context = getContext();
  for (int i = 0; i < pages; i++) {
    RadioButton radioButton = new RadioButton(context);
    radioButton.setLayoutParams(buttonLayoutParams);
    radioButton.setButtonDrawable(android.R.color.transparent);
    radioButton.setBackgroundResource(R.drawable.wizard_custom_indicator);
    radioButton.setClickable(false);
    radioGroup.addView(radioButton);
    wizardButtons.add(radioButton);
  }
}
 
Example 3
Source File: SearchActivity.java    From Car-Pooling with MIT License 6 votes vote down vote up
/**
 * This method is used to display all the rides available to specific destination
 * @param rideInfos all the rides that are available
 */
private void addRadioButton(RideInfo[] rideInfos) {

    RadioGroup radioGroup= (RadioGroup) findViewById(R.id.RadioButtonGroup);
    RadioGroup.LayoutParams rprms;
    radioGroup.removeAllViews();

    if(rideInfos.length>0)
    {
        for(int i=0;i<(rideInfos.length);i++){
            RadioButton radioButton = new RadioButton(this);
            radioButton.setText("CAR NO- " + rideInfos[i].getCar_Num() + " -Source- " + rideInfos[i].getSource() + " -Destination- " + rideInfos[i].getDestination() + " -Time- " + rideInfos[i].getRideTime());
            radioButton.setId(i);
            rprms= new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.WRAP_CONTENT);
            radioGroup.addView(radioButton, rprms);
        }
    }
    else
    {
        Toast.makeText(SearchActivity.this, "No Rides available to destination.. Please try again", Toast.LENGTH_SHORT).show();
    }
}
 
Example 4
Source File: RadioGroup1.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.radio_group_1);
    mRadioGroup = (RadioGroup) findViewById(R.id.menu);

    // test adding a radio button programmatically
    RadioButton newRadioButton = new RadioButton(this);
    newRadioButton.setText(R.string.radio_group_snack);
    newRadioButton.setId(R.id.snack);
    LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
            RadioGroup.LayoutParams.WRAP_CONTENT,
            RadioGroup.LayoutParams.WRAP_CONTENT);
    mRadioGroup.addView(newRadioButton, 0, layoutParams);

    // test listening to checked change events
    String selection = getString(R.string.radio_group_selection);
    mRadioGroup.setOnCheckedChangeListener(this);
    mChoice = (TextView) findViewById(R.id.choice);
    mChoice.setText(selection + mRadioGroup.getCheckedRadioButtonId());

    // test clearing the selection
    Button clearButton = (Button) findViewById(R.id.clear);
    clearButton.setOnClickListener(this);
}
 
Example 5
Source File: NavView.java    From TabPager with Apache License 2.0 5 votes vote down vote up
/**
 * 设置适配器
 *
 * @param adapter 适配器
 */
public void setAdapter(NavAdapter adapter) {
    //动态生成菜单
    int pageCount = adapter.getCount();
    RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.MATCH_PARENT, 1);
    //先移除所有的菜单项
    rgTabs.removeAllViews();
    for (int i = 0; i < pageCount; i++) {
        BadgeRadioButton tab = (BadgeRadioButton) LayoutInflater.from(getContext()).inflate(R.layout.view_nav_tab, null);
        tab.setLayoutParams(params);
        tab.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(adapter.getTabIconId(i)), null, null);
        tab.setText(adapter.getPageTitle(i));
        tab.setTextColor(mNavTextDefaultColor);
        tab.setTag(i);
        tab.getBadgeViewHelper().setBadgeBgColorInt(mBadgeBgColor);
        tab.getBadgeViewHelper().setBadgeTextColorInt(mBadgeTextColor);
        tab.getBadgeViewHelper().setDragEnable(mBadgeDragEnable);

        rgTabs.addView(tab, i);
    }

    //从适配器获取页面缓存
    mCache = adapter.getPagerCache();

    //设置ViewPager适配器
    vpContent.setAdapter(adapter);

    //设置默认选中的菜单选项
    ((RadioButton) rgTabs.getChildAt(vpContent.getCurrentItem())).setChecked(true);
    //设置选中项样式
    setTabStyle((RadioButton) rgTabs.getChildAt(vpContent.getCurrentItem()), true);

    //初始化事件
    initListener();

    //绑定适配器与NavView,为了在适配器中能获取到NavView中的某些数据,比如当前页面
    adapter.bindTpgView(this);
}
 
Example 6
Source File: NewSensorLocation.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void AddButton(String text, int id) {
    RadioButton newRadioButton = new RadioButton(this);
    newRadioButton.setText(text);
    newRadioButton.setId(id);
    LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
            RadioGroup.LayoutParams.WRAP_CONTENT,
            RadioGroup.LayoutParams.WRAP_CONTENT);
    radioGroup.addView(newRadioButton);

}
 
Example 7
Source File: NewSensorLocation.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void AddButton(String text, int id) {
    RadioButton newRadioButton = new RadioButton(this);
    newRadioButton.setText(text);
    newRadioButton.setId(id);
    LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
            RadioGroup.LayoutParams.WRAP_CONTENT,
            RadioGroup.LayoutParams.WRAP_CONTENT);
    radioGroup.addView(newRadioButton);

}
 
Example 8
Source File: NavView.java    From TabPager with Apache License 2.0 5 votes vote down vote up
/**
 * 设置适配器
 *
 * @param adapter 适配器
 */
public void setAdapter(NavAdapter adapter) {
    //动态生成菜单
    int pageCount = adapter.getCount();
    RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT, RadioGroup.LayoutParams.MATCH_PARENT, 1);
    //先移除所有的菜单项
    rgTabs.removeAllViews();
    for (int i = 0; i < pageCount; i++) {
        BadgeRadioButton tab = (BadgeRadioButton) LayoutInflater.from(getContext()).inflate(R.layout.view_nav_tab, null);
        tab.setLayoutParams(params);
        tab.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(adapter.getTabIconId(i)), null, null);
        tab.setText(adapter.getPageTitle(i));
        tab.setTextColor(mNavTextDefaultColor);
        tab.setTag(i);
        tab.getBadgeViewHelper().setBadgeBgColorInt(mBadgeBgColor);
        tab.getBadgeViewHelper().setBadgeTextColorInt(mBadgeTextColor);
        tab.getBadgeViewHelper().setDragEnable(mBadgeDragEnable);

        rgTabs.addView(tab, i);
    }

    //从适配器获取页面缓存
    mCache = adapter.getPagerCache();

    //设置ViewPager适配器
    vpContent.setAdapter(adapter);

    //设置默认选中的菜单选项
    ((RadioButton) rgTabs.getChildAt(vpContent.getCurrentItem())).setChecked(true);
    //设置选中项样式
    setTabStyle((RadioButton) rgTabs.getChildAt(vpContent.getCurrentItem()), true);

    //初始化事件
    initListener();

    //绑定适配器与NavView,为了在适配器中能获取到NavView中的某些数据,比如当前页面
    adapter.bindTpgView(this);
}
 
Example 9
Source File: NewSensorLocation.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
private void AddButton(String text, int id) {
    RadioButton newRadioButton = new RadioButton(this);
    newRadioButton.setText(text);
    newRadioButton.setId(id);
    LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
            RadioGroup.LayoutParams.WRAP_CONTENT,
            RadioGroup.LayoutParams.WRAP_CONTENT);
    radioGroup.addView(newRadioButton);

}
 
Example 10
Source File: SettingFragment.java    From ClassSchedule with Apache License 2.0 4 votes vote down vote up
private void showThemeDialog() {
    ScrollView scrollView = new ScrollView(getActivity());
    RadioGroup radioGroup = new RadioGroup(getActivity());
    scrollView.addView(radioGroup);
    int margin = ScreenUtils.dp2px(16);
    radioGroup.setPadding(margin / 2, margin, margin, margin);

    for (int i = 0; i < themeColorArray.length; i++) {
        AppCompatRadioButton arb = new AppCompatRadioButton(getActivity());

        RadioGroup.LayoutParams params =
                new RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);

        arb.setLayoutParams(params);
        arb.setId(i);
        arb.setTextColor(getResources().getColor(themeColorArray[i]));
        arb.setText(themeNameArray[i]);
        arb.setTextSize(16);
        arb.setPadding(0, margin / 2, 0, margin / 2);
        radioGroup.addView(arb);
    }

    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            theme = checkedId;
        }
    });

    DialogHelper dialogHelper = new DialogHelper();
    dialogHelper.showCustomDialog(getActivity(), scrollView,
            getString(R.string.theme_preference), new DialogListener() {
                @Override
                public void onPositive(DialogInterface dialog, int which) {
                    super.onPositive(dialog, which);
                    dialog.dismiss();
                    String key = getString(R.string.app_preference_theme);
                    int oldTheme = Preferences.getInt(key, 0);

                    if (theme != oldTheme) {
                        Preferences.putInt(key, theme);
                        ActivityUtil.finishAll();
                        startActivity(new Intent(app.mContext, CourseActivity.class));
                    }
                }
            });
}
 
Example 11
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);
		}
	});
}