为什么会在我的Galaxy Nexus不是我的SVG图像显示? [英] Why won't my SVG image display on my Galaxy Nexus?
问题描述
我想有一个形象是另一个背景,采用SVG-的Android库。当我认为我的三星GALAXY Nexus(4.3,冲刺)图像,背景图像不显示。当我认为它在模拟器上,它的存在正确。我甚至已经删除了前景,这保持不变。这里的XML布局的关键部分:
I'm trying to have one image be a background for another, using the svg-android library. When I view the image on my Samsung Galaxy Nexus (4.3, Sprint), the background image doesn't display. 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:
<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>
和自定义类。注意:我试着从 SVG-的Android 的刀片>没有运气:
And the custom class. Note I tried a tip from svg-android without luck:
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);
}
}
}
最后,这里是从我的Galaxy Nexus的形象,和仿真器。请注意,在背景的区别。
Lastly, here's the image from my Galaxy Nexus, and the emulator. Note the difference in the background.
推荐答案
原来提供的尖端是在正确的方向,但我有一个小错字。硬件加速似乎是罪魁祸首。由于我没有任何复杂的,禁用它就好了。我几乎有正确的解决方案,只是有错误的比较器。更改code如下修正它:
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();
}
}
这篇关于为什么会在我的Galaxy Nexus不是我的SVG图像显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!