android - webview 和 scrollview 的问题

标签 android webview scroll scrollview

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

是否还有其他方法可以将 html 内容显示在某些 View 中?

这是我的 xml View ,我在 Activity 类中添加了图像和 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>

我这样创建 View :

    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;
    }

最佳答案

只需使用具有高度 FillParent 的 ScrollView 添加一个线性布局 height= deviceHeight+imageHeight

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

关于android - webview 和 scrollview 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8941161/

相关文章:

android - 有没有办法将消息从 Android 浏览器传递到应用程序?

iphone - 获取 pdf 文件的页码 Titanium Studio iPhone

Android - 未定义对 cryptopp 的引用

Android 自然传感器方向帮助

android - 如何在使用 Android WebView 加载带有 css 的 xml 时动态更改样式?

javascript - Chrome 上的向左滚动

javascript - 深度链接无限滚动页面

javascript - 设置后 scrollTop 值立即变化

java - 如何确保我的微调器(菜单内)更新我的菜单标题并确保标题完整显示?

android - 如何在Android中打开原始文件夹中的文件