Last active
April 12, 2016 16:28
-
-
Save wviana/ba9949312d8b2c30c8aa64b1f6116de2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//This is what I'm doing but getting RadioButton width as 0. :( | |
public void addPresenter(int icon){ | |
RadioButton presenter = new RadioButton(getContext()); | |
//Configura atributos padrão | |
Drawable drawable = getResources().getDrawable(icon); | |
presenter.setCompoundDrawables(drawable, null, null, null); | |
presenter.setButtonDrawable(null); | |
presenterSelector.addView(presenter); | |
presenter.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); | |
presenter.getLayoutParams().height = presenter.getMeasuredHeight(); | |
presenter.getLayoutParams().width = presenter.getMeasuredWidth(); | |
presenter.requestLayout(); | |
presenterSelector.requestLayout(); | |
//updatePresent | |
} | |
//This method is used later to set each RadioButton background. | |
private void updatePresenterSelectorBackground(){ | |
int childCount = presenterSelector.getChildCount(); | |
for(int i = 0; i < childCount; i++){ | |
View rb = presenterSelector.getChildAt(i); | |
if(i == 0) | |
//rb.setBackgroundColor(0x00000000); | |
rb.setBackgroundResource(R.drawable.presenter_radiobutton_left); | |
else if (i == childCount - 1) | |
rb.setBackgroundResource(R.drawable.presenter_radiobutton_right); | |
else | |
rb.setBackgroundResource(R.drawable.presenter_radiobutton_center); | |
rb.requestLayout(); | |
} | |
presenterSelector.requestLayout(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- This is what I'm trying to do throught code. --> | |
<RadioButton | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:gravity="center" | |
android:padding="8dp" | |
android:background="@drawable/presenter_radiobutton_left" | |
android:button="@null" | |
android:drawableLeft="@drawable/fire" | |
/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment