将任意数量的 WebView 添加到 ScrollView
我有这个问题:
我在 HorizontalScrollVew 中添加 3 个 WebView。
XML
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Scroll"
android:fillViewport="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/container"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"></LinearLayout>
</HorizontalScrollView>
代码
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
LinearLayout container = FindViewById<LinearLayout>(Resource.Id.container);
ScrollView scrollView = FindViewById<HorizontalScrollView>(Resource.Id.Scroll);
scrollView.HorizontalScrollBarEnabled = true;
scrollView.VerticalScrollBarEnabled = false;
int top = 0;
int left = 0;
WebView WebView1 = new WebView(this);
WebView1.LoadUrl("http://...");
WebView1.HorizontalScrollBarEnabled = false;
WebView1.VerticalScrollBarEnabled = false;
this._layoutParams = null;
this._layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.WrapContent);
_layoutParams.SetMargins(left, top, 0, 0);
container.AddView(WebView1, _layoutParams);
WebView WebView2 = new WebView(this);
WebView2.LoadUrl("http://...");
WebView2.HorizontalScrollBarEnabled = false;
WebView2.VerticalScrollBarEnabled = false;
WebView2.SetMinimumWidth(600);
WebView2.SetMinimumHeight(500);
this._layoutParams = null;
this._layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent,LinearLayout.LayoutParams.WrapContent);
left += 300;
_layoutParams.SetMargins(left, top, 0, 0);
container.AddView(WebView2, this._layoutParams);
WebView WebView3 = new WebView(this);
WebView3.LoadUrl("http://...");
WebView3.HorizontalScrollBarEnabled = false;
WebView3.VerticalScrollBarEnabled = false;
WebView3.SetMinimumWidth(600);
WebView3.SetMinimumHeight(500);
this._layoutParams = null;
this._layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent,LinearLayout.LayoutParams.WrapContent);
left += 600;
_layoutParams.SetMargins(left, top, 0, 0);
container.AddView(WebView3, this._layoutParams);
}
但是有WebViews不显示。请告诉我如何正确地将一些 WebView 添加到 HorizontalScrollView 并将它们显示在 fisicalDisplay 上。
谢谢!
I have this problem:
I add 3 WebViews in a HorizontalScrollVew.
XML
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/Scroll"
android:fillViewport="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/container"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"></LinearLayout>
</HorizontalScrollView>
Code
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
LinearLayout container = FindViewById<LinearLayout>(Resource.Id.container);
ScrollView scrollView = FindViewById<HorizontalScrollView>(Resource.Id.Scroll);
scrollView.HorizontalScrollBarEnabled = true;
scrollView.VerticalScrollBarEnabled = false;
int top = 0;
int left = 0;
WebView WebView1 = new WebView(this);
WebView1.LoadUrl("http://...");
WebView1.HorizontalScrollBarEnabled = false;
WebView1.VerticalScrollBarEnabled = false;
this._layoutParams = null;
this._layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent, LinearLayout.LayoutParams.WrapContent);
_layoutParams.SetMargins(left, top, 0, 0);
container.AddView(WebView1, _layoutParams);
WebView WebView2 = new WebView(this);
WebView2.LoadUrl("http://...");
WebView2.HorizontalScrollBarEnabled = false;
WebView2.VerticalScrollBarEnabled = false;
WebView2.SetMinimumWidth(600);
WebView2.SetMinimumHeight(500);
this._layoutParams = null;
this._layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent,LinearLayout.LayoutParams.WrapContent);
left += 300;
_layoutParams.SetMargins(left, top, 0, 0);
container.AddView(WebView2, this._layoutParams);
WebView WebView3 = new WebView(this);
WebView3.LoadUrl("http://...");
WebView3.HorizontalScrollBarEnabled = false;
WebView3.VerticalScrollBarEnabled = false;
WebView3.SetMinimumWidth(600);
WebView3.SetMinimumHeight(500);
this._layoutParams = null;
this._layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FillParent,LinearLayout.LayoutParams.WrapContent);
left += 600;
_layoutParams.SetMargins(left, top, 0, 0);
container.AddView(WebView3, this._layoutParams);
}
But there are WebViews don't displayed. Please tell me how to correctly add a few WebViews to an HorizontalScrollView and display them on fisicalDisplay.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试将网络视图放入线性布局中。
但由于 webview 是可滚动的,我认为您无法实际滚动 ScrollView - 您必须以编程方式滚动它。或者您可以使用 ViewFlipper,这也将允许您使用自定义动画。
You could try putting the webviews into a linear layout.
But as the webviews are scrollable, I don't think you will be able to actually scroll the ScrollView - you will have to scroll it programmatically. Or you could use a ViewFlipper, this will also allow you to use you custom animations.