2012-01-18 2 views
4

RadioGroup의 RadioButtons와 같은 질문에 프로그래밍 방식으로 여러 답변을 추가하고 있습니다 (아래 코드 및 이미지 참조).겹치는 텍스트로 어떻게 RadioButton을 만들 수 있습니까?

거의 달성했지만 텍스트가있는 라디오 버튼이있는 대신 (아래 이미지 참조) 텍스트와 배경 만 갖고 싶습니다.

라디오 버튼을 제거 할 수 있습니까?

또는 현재 배경을 라디오 버튼으로 설정하고 (선택/선택 해제 상태로) 텍스트를 겹쳐서 추가 할 수 있습니까?

RadioGroup answer_container = (RadioGroup) findViewById(R.id.answer_container); 

while (c.isAfterLast() == false) { 

    RadioButton answer = new RadioButton(PCItem.this); 
    answer.setText(c.getString(c.getColumnIndex(DBAdapter.KEY_ANS_TEXT))); 
    answer.setBackgroundResource(R.drawable.btn_ans); 
    answer.setPadding((int)(30 * density), 0, 0, 0); 
    answer.setGravity(Gravity.CENTER_VERTICAL); 
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams((int)(775 * density), (int)(81 * density)); 
    params.setMargins(0, (int)(20*density), 0, 0); 
    answer.setLayoutParams(params); 

    answer_container.addView(answer); 

    c.moveToNext(); 
} 

enter image description here

+0

동일한 문제가 있음에도 불구하고 나를 도와 줄 수 있습니까? – Goofy

답변

0

좋아, 내가 그것을 사용하게하는 올바른 방법은이 StateListDrawable 빈 설정하는 것입니다

answer.setButtonDrawable(android.R.color.transparent); 

버튼을 제거 btn_ans 같은 선택기를 사용한다 :

0123을
4

당신은 radioButton.setButtonDrawable()를 사용할 수 있습니다. StateListDrawable을 사용하여 각 버튼 상태에 다른 드로어 블 (checked/unchecked 포함)을 지정할 수도 있습니다.

완전히 단순히 null으로 설정할 수있는 버튼을 제거하려면 :

<RadioButton 
    android:button="@null" 
    ... 
/> 

코드 radioButton.setButtonDrawable(null);에 의해 작동하지 않습니다 유의하십시오!

radioButton.setButtonDrawable(new StateListDrawable()); 

더 많은 항목이있는 경우, 당신은 RadioButton의 기본 속성 대체 할 사용자 정의 스타일을 만들 수 있습니다 :

<style name="CustomRadioButton" parent="@android:style/Widget.CompoundButton.RadioButton"> 
    <item name="android:button">@null</item> 
    <item name="android:paddingLeft">0dp</item> 
</style> 
+0

라디오 버튼을 설정합니다. 나는 그것을 제거하거나 텍스트를 겹치게하고 싶다. – jul

+0

@jul : 내 마지막 편집을 봐, 내가 원하는 것 같아. –

+0

프로그래밍 방식으로 버튼을 null로 설정하려고 시도했지만 (여전히'answer.setButtonDrawable (null)'), 여전히 나타납니다. – jul

관련 문제