【问题标题】:Add two webview in framelayout在framelayout中添加两个webview
【发布时间】:2012-07-08 02:34:14
【问题描述】:

我想在一个布局中添加两个 webview..我使用 frameLayout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >


    <WebView
        android:id="@+id/webview1"
        android:layout_width="350dip"
        android:layout_height="350dip" />


    <WebView
        android:layout_height="250dip"
        android:layout_width="250dip"
        android:id="@+id/webview2"    
    />

    </FrameLayout>

在主要活动中:

    web1=(WebView)findViewById(R.id.webview1);
    web2=(WebView)findViewById(R.id.webview2);

    web1.loadUrl("http://www.google.com");
    web2.loadUrl("http://www.youtube.com");

    web2.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            Animation anim=AnimationUtils.loadAnimation(FrameWebViewActivity.this, android.R.anim.slide_in_left);
            web2.setAnimation(anim);
        }
    });

但是当运行项目时,它只显示 webview youtube 全屏..我想同时显示两个 webview..我必须做什么??

【问题讨论】:

    标签: android webview android-framelayout


    【解决方案1】:

    使用其他布局,FrameLayout 用于仅显示单个子元素。

    我建议使用线性布局并指定权重以将视图划分为所需的比例。

    【讨论】:

      【解决方案2】:

      在使用 Framelayout 时需要记住的一件事是 “当向 FrameLayout 添加多个视图时,每个视图都将堆叠在前一个视图之上。” 所以最好使用任何其他父布局,例如线性布局或相对布局,其中使用两个框架布局..

      代码:

         </RelativeLayout>
      
            <?xml version=”1.0” encoding=”utf-8”?>
              <RelativeLayout
                 android:id=”@+id/RLayout”
                 android:layout_width=”fill_parent”
                 android:layout_height=”fill_parent”
                 xmlns:android=”http://schemas.android.com/apk/res/android”>
      
               <FrameLayout>
                  <WebView
                    android:id="@+id/webview1"
                    android:layout_width="350dip"
                    android:layout_height="350dip" />
               </FrameLayout> 
      
               <FrameLayout>
                  <WebView
                     android:layout_height="250dip"
                     android:layout_width="250dip"
                     android:id="@+id/webview2" />
              </FrameLayout> 
            </RelativeLayout>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-07-13
        • 1970-01-01
        • 1970-01-01
        • 2016-05-06
        • 1970-01-01
        相关资源
        最近更新 更多