【问题标题】:FrameLayout/WebView ignores fill_parent in dialog themeFrameLayout/WebView 忽略对话框主题中的 fill_parent
【发布时间】:2011-09-02 12:25:11
【问题描述】:

我有一个带有对话框主题的活动。

<activity
    android:name=".MyActivity"
    android:theme="@android:style/Theme.Dialog" />

该 Activity 使用以下 xml 布局:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_article_frame_layout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#000000">
    <WebView
        android:id="@+id/activity_article_web_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
    <Button
    android:id="@+id/activity_article_close_button"
        android:layout_width="25dip"
        android:layout_height="26dip"
        android:layout_marginTop="5dip"
        android:layout_marginRight="5dip"
        android:layout_gravity="right|top"
        android:background="@drawable/close_button" />
</FrameLayout>

WebView 的内容将从 sdcard 上的存储文件加载(内容作为意图数据提供)。这发生在 onCreate() 中:

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_article);

    // Handle to the WebView
    mWebView = (WebView) findViewById(R.id.activity_article_web_view);
    initWebView();
    mWebView.loadDataWithBaseURL(null, myHtmlContent, "text/html", "utf-8", null);

    // Handle to the close button
    mCloseButton = (Button) findViewById(R.id.activity_article_close_button);
    mCloseButton.setOnClickListener(this);
}

项目详情: minSDK: 7 (2.1)

我的问题是,WebView 和/或 FrameLayout 没有 fill_parent。活动的高度与按钮使用的高度完全相同。我几乎无法阅读页面的第一行。我的问题只发生在蜂窝 3.x 上。下面 (

我尝试动态创建 WebView。我试图在 onCreate() 中设置 LayoutParams。没有改变。我也尝试在 FrameLayout 和 WebView 上调用 invalidate() 但结果是一样的......

【问题讨论】:

    标签: android webview invalidation android-framelayout fill-parent


    【解决方案1】:

    这个解决方案对我有用:

    How can I get a Dialog style activity window to fill the screen?

        @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.your_layout);
    
        getWindow().setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    }
    

    【讨论】:

      【解决方案2】:

      尝试将RelativeLayout用作FrameLayout,也许它会起作用。 我不知道 FrameLayout 是否接受 fill_parent。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-06-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多