Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Listview的XML布局膨胀失败_Android_Xml_Android Layout_Listview - Fatal编程技术网

Android Listview的XML布局膨胀失败

Android Listview的XML布局膨胀失败,android,xml,android-layout,listview,Android,Xml,Android Layout,Listview,我一直在尝试使用自定义适配器使listview的这种自定义xml布局永远工作(呈现)。没有抛出错误,顶部的textview只是拒绝渲染(我在android设备管理器中进行了检查)。 我还在getView函数中对其进行了调试,并确保正确填充了对象列表,并且textview上的findviewbyid工作正常 这里是xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:lay

我一直在尝试使用自定义适配器使listview的这种自定义xml布局永远工作(呈现)。没有抛出错误,顶部的textview只是拒绝渲染(我在android设备管理器中进行了检查)。 我还在getView函数中对其进行了调试,并确保正确填充了对象列表,并且textview上的findviewbyid工作正常

这里是xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="5dp"
android:background="@drawable/itembackground">

<ImageView
    android:id="@+id/itemicon"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    android:layout_alignParentTop="true"
    android:layout_marginRight="6dip" />

<TextView
    android:id="@+id/itemtopLine"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_above="@+id/itembotLine"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@id/itemicon"
    android:ellipsize="marquee"
    android:singleLine="true"
    android:textSize="16sp" />

<TextView
    android:id="@+id/itembotLine"
    android:layout_width="fill_parent"
    android:layout_height="20dp"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_toRightOf="@id/itemicon"
    android:ellipsize="marquee"
    android:singleLine="true"
    android:textSize="12sp" />
</RelativeLayout>

你能发布你的太空项目代码吗?这是适配器。问题几乎总是在适配器中。你能发布它吗?你想让图像视图在左边,文本视图在右边,一个在顶部,另一个在底部,如果是的话,试着为图像视图设置一个宽度,比如100dp,并更改两个文本视图的宽度以匹配父视图,看看这是否有帮助图像视图是项目的背景?谢谢大家的帮助,我解决了这个问题。结果表明,我的布局膨胀方法没有使用带null的双参数构造函数。我仍然不知道为什么会导致顶视图消失。
public class SpaceAdapter extends ArrayAdapter<SpaceItem>{
     public SpaceAdapter(Context context, int resource, ArrayList<SpaceItem>       items) {
    super(context, resource, items);
     }

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;

    if (v == null){
        v = LayoutInflater.from(getContext()).inflate(R.layout.space_item, null);
    }

    SpaceItem item = getItem(position);

    ImageView icon = (ImageView) v.findViewById(R.id.itemicon);
    TextView name = (TextView) v.findViewById(R.id.itemtopLine);
    TextView prop = (TextView) v.findViewById(R.id.itembotLine);

    if (item != null){
        icon.setImageDrawable(item.spaceItemIcon);
        name.setText(item.spaceItemName);
        prop.setText(item.spaceItemDescription);
    }
    else {
        icon.setImageDrawable(getContext().getResources()
                                          .getDrawable(android.R.drawable.btn_star, null));
        name.setText("Default");
        name.setText("kek");
    }

    return v;
}
}
public class SpaceItem {
    public Drawable spaceItemIcon;
    public String spaceItemName;
    public String spaceItemDescription;
    public SpaceItem (Drawable ico, String name, String d){
        spaceItemDescription = d;
        spaceItemIcon = ico;
        spaceItemName = name;
        }
    }