webview和scrollview问题

时间:2012-01-20 12:03:27

标签: android webview scroll scrollview

我无法使用scrollView和webView解决我的问题, 我知道,我不能把webview放到scrollview中,但我不知道如何跳转它。 在我的scrollView中,我有图像(1280 x 1300>),这个图像必须滚动,在图像下我必须有带html内容的webview。你知道我应该怎么做吗?

是将html内容放到某个视图中的另一种方法吗?

这是我的xml视图,我在我的活动类

中添加了图像和webview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainLinear"
android:orientation="vertical" >

<RelativeLayout
    android:id="@+id/relativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ProgressBar
            android:id="@+id/progressBar1"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <ScrollView
            android:id="@+id/scroll_journal_page"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
        </ScrollView>

        <Gallery
            android:id="@+id/listview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="#d5d5d3" />
    </RelativeLayout>
</RelativeLayout>

</LinearLayout>

我创造了这样的观点:

    protected void onPostExecute(Bitmap result) {
        Animation fadeInAnimation = AnimationUtils.loadAnimation(Journal.this, R.anim.fade_in);

        relativeLayout = new LinearLayout(getApplicationContext());
        relativeLayout.setLayoutParams(new FrameLayout.LayoutParams(WIDTH, result.getHeight() + HEIGHT));
        relativeLayout.setOrientation(1);
        coverImage = new ImageView(getApplicationContext());
        coverImage.setImageBitmap(result);

        relativeLayout.addView(coverImage);
        Integer pageNumber = Integer.valueOf(ArrayHelper.journalList.get(pageIdentity).get("pageId").toString());
        File file = new File(Environment.getExternalStorageDirectory() + "/MCW/"+ pageNumber +"/content.html");
        if(file.exists()) {
            LinearLayout linearLayout = new LinearLayout(getApplicationContext());
            linearLayout.setLayoutParams(new FrameLayout.LayoutParams(WIDTH, HEIGHT));
            WebView wV = new WebView(getApplicationContext());
            try {
                InputStream fin = null;
                int len;
                fin = new BufferedInputStream(new FileInputStream(file));
                byte[] buffer = new byte[fin.available()];
                len = fin.read(buffer);
                fin.close();
                String rawText = EncodingUtils.getString(buffer, 0, len, "utf-8");
                wV.loadDataWithBaseURL("", rawText, "text/html", "utf-8", null);
            }catch (Exception e) {}
            linearLayout.addView(wV);
            relativeLayout.addView(linearLayout);
        }
        scrollview.addView(relativeLayout);
        scrollview.setAnimation(fadeInAnimation);
        isReadyToChange = true;
    }

3 个答案:

答案 0 :(得分:0)

只需使用带有高度FillParent的Scrollview 添加linearlayout height = deviceHeight + imageHeight

使用具有设备高度的线性布局 将webview添加到此linearlayout 将图像和linearlayout添加到此布局

答案 1 :(得分:0)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<ScrollView android:layout_width="wrap_content"
android:layout_height="fill_parent">

<LinearLayout android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <ImageView android:id="@+id/pho"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/dd1"/>

    <WebView android:id="@+id/webView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

</ScrollView>

</RelativeLayout>

答案 2 :(得分:0)

我不确定这是否符合您的要求,但是

is any another way to put html content with to some view ?

您可以使用TextView来显示HTML内容

mTextView.setText(Html.fromHtml('html_content'));

同时浏览Mark Murphy - HTML Tags Supported By TextView

作为旁注,HTML也可以用作字符串资源,如Here

所述