我正在尝试创建一个小部件来显示从 XML 文件解析的项目。最后,将显示原始项目的图像、标题和 URL。但是,现在我正在处理布局,添加 ImageView
后出现运行时错误到它的容器。 <RelativeLayout android:id="@+id/newsdviewlayout"
位于主布局的 Root View (RelativeLayout
)内。请帮忙。
<RelativeLayout
android:id="@+id/newsdviewlayout"
style="@style/newsviewstyle"
android:layout_alignParentBottom="true">
<ImageView
android:id="@+id/newsviewimg" />
</RelativeLayout>
最佳答案
是的,我想你错过了必需的属性 android:layout_width=""
和 android:layout_height=""
,所以对于你的情况,xml 就像这个:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/newsdviewlayout"
style="@style/newsviewstyle"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true">
<ImageView
android:id="@+id/newsviewimg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
或者对于 RelativeLayout
,您也可以将 2 属性放在 newsviewstyle
样式中。
关于android - 将 ImageView 添加到 RelativeLayout 会导致运行时异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6876104/