Я пытаюсь, чтобы одно изображение было фоном для другого, используя библиотеку svg-android. Когда я просматриваю изображение на своем Samsung Galaxy Nexus (4.3, Sprint), фоновое изображение не отображается. Когда я просматриваю его на эмуляторе, он там правильно. Я даже удалил передний план, и это остается неизменным. Храньте ключевые слова в XML-макете:Почему мой экран SVG не отображается на моем Galaxy Nexus?
<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 без везения:
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, и эмулятор. Обратите внимание на разницу в фоновом режиме.
Я имею проблему в этом вопросе http://stackoverflow.com/questions/20400697/canvas-is-not-showing-image-drawable-andorid. можете ли вы мне помочь в решении этой проблемы? – User42590