【发布时间】:2016-01-21 17:05:32
【问题描述】:
我在将 imageButton 设置为 WebView 的左上角时遇到问题,我不知道如何使用布局(线性或相对),我尝试了很多代码块,但没有一个对我有用.
这就是我创建图像按钮的方式;
ImageButton mImageButton = new ImageButton(context);
mImageButton.setImageResource(R.drawable.close_button);
mImageButton.setLayoutParams(new ViewGroup.LayoutParams(width, height));
mImageButton.setAdjustViewBounds(true);
mImageButton.setBackgroundDrawable(null);
mImageButton.setScaleType(ImageView.ScaleType.FIT_CENTER);
这就是我创建图像按钮并将其添加到 webview 的方式
WebView mWebView = new WebView(context);
mWebView.loadData(htmlContent, "text/html", "UTF-8");
mWebView.addView(mImageButton);
关于如何在不使用 xml 的情况下正确放置它的任何想法,因为我正在尝试为将要分发的 jar 文件执行此操作
【问题讨论】:
-
为什么不用xml中的布局文件?
-
@sonic 哦,我应该在问题中说,我正在创建一个将用于其他人的 jar 文件,所以这不是一个选项
-
根据图片你可以使用这种类型的视图布局
-
@Naveen 是对的,您可以使用框架布局并在该框架布局中放置 webview 和 imageview
-
如何@Harish 正如我在“我不知道如何使用布局”问题中所写的那样
标签: android android-layout webview android-relativelayout android-imagebutton