1

我希望在里面渲染这样的东西RadioGroup

(X) - (网页视图)

(X) - (网页视图)

(X) - (网页视图)

(X) - (网页视图)

其中 (X) 是 RadioButton

WebView 的内容可以是非常小的格式化文本,也可以是图像。

我写了以下代码

LinearLayout ll = (LinearLayout) findViewById(R.id.ll);

RadioGroup radioGroup = new RadioGroup( getApplicationContext() );
radioGroup.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT ));

for( int j = 0; j < 4; j++ )
{
    RadioButton optionRadioButton = new RadioButton(this);
LinearLayout.LayoutParams p = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT );
optionRadioButton.setLayoutParams( p );

    radioGroup.addView(optionRadioButton);

    WebView optionWebView = new WebView( getApplicationContext() );
    optionWebView.loadDataWithBaseURL(URL, webViewData, "text/html", null, null);
    p = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT );
    optionWebView.setLayoutParams( p );
    radioGroup.addView( optionWebView );
}

ll.addView( radioGroup );   

我得到的输出是这样的。(X)

(网络视图)

(X)

(网络视图)

(X)

(网络视图)

(X)

(网络视图)

我希望RadioButtonandWebView显示在同一行。

我尝试将RadioButtonandWebView组合放在一个LinearLayout容器中,该容器可以正确显示文本,但RadioGroup功能会受到影响。

我也尝试过使用类似的东西

optionRadioButton.setText( Html.fromHtml( webViewData ) );

当我尝试在 webViewData 中发送图像时,这件事无法正常工作。

我也尝试了一些重力,setOrientation,但似乎没有任何效果。我在这里错过了一些非常基本的东西吗?请帮忙。

4

2 回答 2

0
Do this way..   

 RadioGroup radioGroup = new RadioGroup(getApplicationContext());
            radioGroup.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

            for (int j = 0; j < 4; j++) {
                LinearLayout lnr=new LinearLayout(this);
                RadioButton optionRadioButton = new RadioButton(this);
                LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                optionRadioButton.setLayoutParams(p);


                lnr.addView(optionRadioButton);

                WebView optionWebView = new WebView(getApplicationContext());
                optionWebView.loadDataWithBaseURL(URL, webViewData, "text/html", null, null);
                p = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
                optionWebView.setLayoutParams(p);
                lnr.addView(optionWebView);
                radioGroup.addView(lnr);

            }

            ll.addView(radioGroup);
于 2013-09-20T12:37:34.137 回答
0

我知道这个问题被问到已经很久了。但是谁来这个页面有相同的问题陈述可以检查这个方法来解决问题

我有同样的问题。我通过使用这个美丽的图书馆解决了这个问题。

https://github.com/worker8/RadioGroupPlus#downloadinstall

而不是 Android 的 Radio 组,只需使用这个库的 Custom Radio 组。它结合了这个特定组内的所有单选按钮,并将其视为自己的直接子级。所以即使它在两个层次里面也没问题。

对于所有被迫一起使用网络视图和单选按钮的人来说,可以使用这个特定的库。干杯!

于 2017-02-04T10:53:46.867 回答