简体   繁体   English

为什么我的SVG图片无法在我的Galaxy Nexus上显示?

[英]Why won't my SVG image display on my Galaxy Nexus?

I'm trying to have one image be a background for another, using the svg-android library. 我正在尝试使用svg-android库将一个图像作为另一个图像的背景。 When I view the image on my Samsung Galaxy Nexus (4.3, Sprint), the background image doesn't display. 当我在Samsung Galaxy Nexus(4.3,Sprint)上查看图像时,背景图像不显示。 When I view it on the emulator, it's there correctly. 当我在模拟器上查看它时,它正确存在。 I've even removed the foreground, and this stays the same. 我什至删除了前景,并且保持不变。 Here's the key parts of the XML layout: 这是XML布局的关键部分:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >

    <com.kd7uiy.hamfinder.SvgView
        android:id="@+id/svgImage"
        android:src="@raw/paper"
        android:layout_alignLeft="@+id/scroll"
        android:layout_alignRight="@id/scroll"
        android:layout_alignTop="@id/scroll"
        android:layout_above="@+id/buttons"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <ScrollView
            android:id="@+id/scroll"
            android:scrollbars="none"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/buttons"
            android:layout_alignParentLeft="true"
            android:layout_alignParentRight="true"
            android:background="@android:color/transparent"
            android:layout_below="@id/adView">
        <TableLayout
            android:id="@+id/tableView"
                android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:shrinkColumns="1"
            android:stretchColumns="1"
        />
    </ScrollView>
</RelativeLayout>

And the custom class. 和自定义类。 Note I tried a tip from svg-android without luck: 注意我尝试了svg-android的技巧而没有运气:

public class SvgView extends View {

    Picture picture;

    long startTime;
    float scaleFactor;

    public SvgView(Context context,AttributeSet attrs) {
        super(context,attrs);
        setImage(attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android","src", 0));
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        {
            disableHardwareAcceleration();
        }
    }

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void disableHardwareAcceleration()
    {
        setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }

    public SvgView(Context context) {
        super(context);

    }

    public void setImage(int img_resource)
    {
        // Parse the SVG file from the resource
        SVG svg = SVGParser.getSVGFromResource(getResources(),img_resource);
        picture = svg.getPicture();
    }

    public void onDraw(Canvas canvas) {
        if (picture!=null)
        {
            scaleFactor=Math.min((float)getHeight()/picture.getHeight(),(float)getWidth()/picture.getWidth());
            canvas.scale((float)scaleFactor,(float)scaleFactor);
            canvas.drawPicture(picture);
        }

    }
}

Lastly, here's the image from my Galaxy Nexus, and the emulator. 最后,这是我的Galaxy Nexus和模拟器的图片。 Note the difference in the background. 注意背景的不同。

在此处输入图片说明

在此处输入图片说明

It turns out the provided tip was in the right direction, but I had a small typo. 事实证明,所提供的提示方向正确,但我有一个小的错字。 The hardware acceleration seems to be the culprit. 硬件加速似乎是罪魁祸首。 As I don't have anything that complex, disabling it is just fine. 由于我没有那么复杂,禁用它就可以了。 I almost had the right solution, just had the wrong comparitor. 我几乎有正确的解决方案,只是有错误的比较器。 Changing the code as follows fixes it: 如下更改代码即可解决:

public SvgView(Context context,AttributeSet attrs) {
    super(context,attrs);
    setImage(attrs.getAttributeResourceValue("http://schemas.android.com/apk/res/android","src", 0));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
    {
        disableHardwareAcceleration();
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的android项目中的Eclipse无法检测到我的Galaxy Nexus? - Why my Galaxy Nexus is not detected by Eclipse in my android project? 为什么我的应用程序不适用于Galaxy Nexus用户,即使它已经过去了? - Why is my app not available to Galaxy Nexus users, even though it was in the past? 为什么在我的Galaxy Nexus相机上使用此示例比较慢? - Why using this sample on my Galaxy Nexus camera is slow? 亚行不承认我的Galaxy Nexus - Win7 - ADB doesn't recognize my Galaxy Nexus - Win7 无法在Play上安装我的第一个应用。 受支持设备之间的Galaxy Nexus,但显然不是我的Nexus - Can't install my first app on Play. Galaxy Nexus between Supported Devices, but apparently not my Nexus Eclipse不再识别我的Nexus 5 - Eclipse won't recognize my Nexus 5 anymore 为什么我的列表视图不显示? - Why won't my listview display? 为什么Eclipse / adb不会在我的Mac上检测到我的三星Galaxy Tab设备? - Why won't Eclipse/adb detect my Samsung Galaxy Tab device on my Mac? 为什么我的 canvas 不显示 (Android)? - Why won't my canvas display (Android)? 为什么我拍摄的照片不显示在我的imageview中 - Why won't my taken picture display on my imageview
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM