Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ScrollView不使用Drawables Android_Android_Orientation_Scrollview_Drawable_Tablelayout - Fatal编程技术网

ScrollView不使用Drawables Android

ScrollView不使用Drawables Android,android,orientation,scrollview,drawable,tablelayout,Android,Orientation,Scrollview,Drawable,Tablelayout,我正在使用Html.fromHtml获取内容并将其显示在我的活动中。为了做到这一点,我使用了一个ImageGetter。我遇到了一个问题,如果手机无法连接到互联网,应用程序就会崩溃,因为图片无法加载。相反,我希望在我的ldpi/mdpi/…etc文件夹中保存一个占位符图像,当图片无法加载时,可以插入该图像 我的ImageGetter使用URLImageParser,它具有以下onPostExecute方法: @Override protected void onPostExecu

我正在使用Html.fromHtml获取内容并将其显示在我的活动中。为了做到这一点,我使用了一个ImageGetter。我遇到了一个问题,如果手机无法连接到互联网,应用程序就会崩溃,因为图片无法加载。相反,我希望在我的ldpi/mdpi/…etc文件夹中保存一个占位符图像,当图片无法加载时,可以插入该图像

我的ImageGetter使用URLImageParser,它具有以下onPostExecute方法:

    @Override
    protected void onPostExecute(Drawable result) {
        //check to see if an image was found (if not could
        //be due to no internet)
        if(result ==null){
            //the drawable wasn't found so use the image not found
            //png
            Drawable imageNotFound = a.getResources().getDrawable(R.drawable.image_not_found);
            result = imageNotFound;
        }

        intrinsicHeight = result.getIntrinsicHeight();
        intrinsicWidth = result.getIntrinsicWidth();

        DisplayMetrics dm = new DisplayMetrics();
        ((WindowManager) c.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getMetrics(dm);
        int width = dm.widthPixels -50;
        int height = width * intrinsicHeight / intrinsicWidth;

        result.setBounds(0, 0, 0 + width, 0 
                + height);

        urlDrawable.setBounds(0, 0, 0+width, 0+height);  

        // change the reference of the current drawable to the result 
        // from the HTTP call 
        urlDrawable.drawable = result; 

        // redraw the image by invalidating the container 
        URLImageParser.this.container.invalidate();

        // For ICS
        URLImageParser.this.container.setHeight((URLImageParser.this.container.getHeight() 
        + height));

        // Pre ICS
        URLImageParser.this.container.setEllipsize(null);
    }
我只是在这个方法的顶部插入了ifresult==null语句。但是现在如果图片可以加载,应用程序就可以完美地工作。如果无法加载图像,而使用占位符,我会得到一些奇怪的行为

scrollview从不滚动到屏幕的底部,我不知道这是为什么。理论上,我的imageNotFound drawable(一个png文件)和从互联网下载的文件应该没有区别。滚动视图只会稍微移动

我不知道是什么原因造成的。在网上搜索时,大多数人似乎都对相对论存在问题。我找不到任何人在抽屉或桌子布局方面有问题

我的布局xml如下所示:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
  android:layout_width="match_parent"
  android:layout_height="fill_parent"
  android:paddingBottom = "0dip"
  android:orientation = "vertical" >


<TableLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="0,1"
    android:shrinkColumns="0,1"
    android:id = "@+id/SharedTableLayout"
    android:paddingBottom = "0dip" >

    <TableRow
         android:layout_height="wrap_content"
         android:layout_width="match_parent"
         android:paddingBottom = "0dip">
         <TextView
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:id = "@+id/SharedTableContent"
             android:layout_span="2"
             android:gravity = "left"
             android:paddingLeft = "10dip"
             android:paddingRight = "10dip"
             android:paddingTop = "20dip"
             android:paddingBottom = "0dip"/>
    </TableRow>

</TableLayout>


</ScrollView>
我真的很感激任何关于这方面的建议,我已经坚持了好几个星期了

谢谢你的时间


id为SharedTableContent的TextView显示一个字符串,该字符串是使用html.fromHtml从html转换而来的,因此图像可能被文本包围,这意味着我无法将解决方案硬编码为xml,因为无法预知要提前下载多少图像,这一切都是通过编程完成的。

尝试更改scrollview的布局宽度以匹配父视图

android:layout\u width=match\u parent android:layout\u height=match\u parent

或者试试这个

<?xml version="1.0" encoding="utf-8"?>
<ScrollView android:id="@+id/ScrollView02" 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            xmlns:android="http://schemas.android.com/apk/res/android">
<HorizontalScrollView android:id="@+id/HorizontalScrollView01" 
                      android:layout_width="wrap_content" 
                      android:layout_height="wrap_content">
<ImageView android:id="@+id/ImageView01"
           android:src="@drawable/pic" 
           android:isScrollContainer="true" 
           android:layout_height="fill_parent" 
           android:layout_width="fill_parent" 
           android:adjustViewBounds="true">
</ImageView>
</HorizontalScrollView>
</ScrollView>

奇怪的是,这使得它比平时滚动得更远,直到我旋转手机。然后它几乎和以前一样不旋转了。我还添加了android:fillViewport=true,它似乎也没有任何作用。在另一个ScrollView中使用ScrollView是一个非常糟糕的想法。我不认为我可以用这样的xml编写代码。id为SharedTableContent的textview用于显示html中的字符串,该字符串可能包含图像,也可能不包含图像。图像可以在文本块之间。谢谢你的建议,顺便说一句,而不是ScrollView。为什么你不试着用任何具体的理由来加载图像呢?或者我对android比较陌生,我从来没有听说过ListView。它会自动滚动吗?是的,当然它会垂直滚动。当我将id为SharedTableContent的内容放入Textview时,它不仅仅是图像,它是文本,文本块之间可能有图像,也可能没有图像。所以我使用Html.fromHtml来显示它。为了让列表视图正常工作,我是否需要拆分内容,以便每个列表项都是文本块或图像?谢谢你的帮助,我不认为ListView会起作用,因为我需要同时显示图像和文本,而且我不希望每个元素都可以自己滚动