我想弄清楚如何以编程方式在相对布局右侧设置带有图标的webview列表。 我有相对布局作为父级,我在这个布局下以编程方式添加新的相对布局我们需要在webview右侧放置一个图标,代码是
for(final OptionPOJO option: questionPOJO.getOptions()) {
LinearLayout.LayoutParams mainparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
mainparams.setMargins(10, 10, 10, 10);
final RelativeLayout linearLayout = new RelativeLayout(getContext());
linearLayout.setLayoutParams(mainparams);
linearLayout.requestLayout();
final WebView optionview = new WebView(getContext());
optionview.getSettings().setDomStorageEnabled(true);
optionview.getSettings().setSaveFormData(true);
optionview.getSettings().setAllowContentAccess(true);
optionview.getSettings().setAllowFileAccess(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
optionview.getSettings().setAllowFileAccessFromFileURLs(true);
optionview.getSettings().setAllowUniversalAccessFromFileURLs(true);
}
optionview.setWebViewClient(new WebViewClient());
optionview.setClickable(true);
optionview.getSettings().setJavaScriptEnabled(true);
optionview.setBackgroundColor(0);
optionview.setWebChromeClient(new WebChromeClient());
//optionview.getSettings().setStandardFontFamily("Roboto-Medium");
linearLayout.setBackground(getResources().getDrawable(R.drawable.button_bg));
optionview.getSettings().setTextSize(WebSettings.TextSize.NORMAL);
optionview.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return true;
}
});
optionview.setLongClickable(false);
optionview.setHapticFeedbackEnabled(false);
String optionhead = "<head>" +
"<style>body {font-family: 'Lato';, font-size: 6.75pt; background-color: yellow; color: red; src: url('file:///android_asset/fonts/Lato-Regular.ttf');color:black;}</style></head>";
String optionhtmlData = "<html>" + optionhead + "<body>" + option.getText() + "</body></html>";
optionview.loadDataWithBaseURL("file:///android_asset/", optionhtmlData, "text/html", "utf-8", null);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(5, 5, 5, 5);
optionview.setLayoutParams(params);
linearLayout.addView(optionview);
button_layout.addView(linearLayout);
}