Alexadnr
Alexadnr

Reputation: 83

Add any number of WebViews to a ScrollView

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!

Upvotes: 0

Views: 1113

Answers (1)

Matthew
Matthew

Reputation: 5222

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.

Upvotes: 1

Related Questions