【发布时间】:2014-08-25 17:18:15
【问题描述】:
我尝试在我的 android 应用中使用滚动图像,但在调试器中出现此错误:
Binary xml error in line 10 :inflating android widget imageview
这是xml代码
<?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:background="@drawable/bgabout">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/aboutscroll" />
</ScrollView>
</LinearLayout>
这是堆栈跟踪:
08-26 11:43:58.102: E/AndroidRuntime(24553): 致命异常: main 08-26 11:43:58.102:
E/AndroidRuntime(24553):java.lang.RuntimeException:无法启动活动 ComponentInfo{com.example.albir/com.example.albir.About}:android.view.InflateException:二进制 XML 文件第 10 行:膨胀类 android.widget.ImageView 时出错
我使用了指南并进行了相同的更改,所以现在我只能滚动具有 700*1900 像素而不是这么大的图像,调试器显示此跟踪:异常内存不足此代码:
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</ScrollView>
</HorizontalScroll>
java 类
public class About extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
ImageView iv = (ImageView) findViewById(R.id.imageView1);
Resources res = getResources();
BitmapDrawable bitmap = (BitmapDrawable) res.
getDrawable(R.drawable.aboutscroll);
int imgW = bitmap.getIntrinsicWidth();
int imgH = bitmap.getIntrinsicHeight();
iv.setImageDrawable(bitmap);
ViewGroup.LayoutParams params = (ViewGroup.LayoutParams) iv.getLayoutParams();
params.width = imgW;
params.height = imgH;
}
}
我想知道我是否可以修改此代码以显示更大的图像
【问题讨论】:
-
任何回复请想法
-
尝试设置
android:src="@drawable/aboutscroll"并删除android:background -
认为你我改变了但总是相同的 pb 第 10 行中的相同错误
-
你能发布完整的堆栈跟踪吗?
-
好的,我有这个堆栈跟踪:无法启动活动 ComponentInfo {} android 异常:Binary xml line #10: error inflating class android.widget.imageview
标签: imageview scrollview