android - 将 ImageView 添加到 RelativeLayout 会导致运行时异常

标签 android

我正在尝试创建一个小部件来显示从 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/

相关文章:

android - ShapeableImageView 的笔画被边框切割

android - 我无法推送通知

android - 内核空间如何向用户空间发送命令和数据?

android - Jtransforms,输出频率不准确。

java - 在 onPostExecute 上的 AsyncTask 中,textview 值未设置

java - 分配 AsyncTask 返回的值

android - 插入或更新到 SQLite 但仅当其中一个值满足条件时才更新

android - 导入项目(Eclipse ADT,Gradle等)选项在Android Studio 2.3.2中不会退出

android - 要求用户打开位置

安卓工作室 : Shutdown Ubuntu 15. 10