将任意数量的 WebView 添加到 ScrollView

发布于 2024-12-04 04:07:48 字数 2895 浏览 0 评论 0原文

我有这个问题:

我在 Horizo​​ntalScrollVew 中添加 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 添加到 Horizo​​ntalScrollView 并将它们显示在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月隐月明月朦胧 2024-12-11 04:07:48

您可以尝试将网络视图放入线性布局中。
但由于 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文