简体   繁体   English

Android Studio中的ListView预览

[英]ListView preview in android studio

EDIT : this issue now only happens when I try to have a listview with a preview layout that contains databinding (from android databinding) 编辑:现在仅当我尝试使用包含数据绑定(来自android数据绑定)的预览版式的listview时,才会发生此问题

In android Studio, when I try to add an item preview for a listview, nothing happens (the default preview is still displayed) and in the splitted version (text + preview) I have a black screen for the preview. 在android Studio中,当我尝试为列表视图添加项目预览时,什么也没发生(默认预览仍显示),在拆分版本(文本+预览)中,我的预览黑屏。 First I was thinking that my layout was somehow too complex, so I tried with a simple layout file, containing only a LinearLayout and a listview. 首先,我以为布局有点过于复杂,因此我尝试了一个仅包含LinearLayout和listview的简单布局文件。 I checked that the listview has an id (and all the solutions I found on stackoverflow) but nothing works. 我检查了listview是否有一个id(以及我在stackoverflow上找到的所有解决方案),但是没有任何效果。 Here is my layout : 这是我的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.com/tools"
              android:orientation="vertical"
              android:layout_width="match_parent"
              android:layout_height="match_parent">


    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/listView2"
        android:layout_gravity="center_horizontal"
        tools:listitem="@layout/item_chat"/>
</LinearLayout>

And here is the screenshot of the result (the preview is supposed to be on the right). 这是结果的屏幕截图(预览应该在右侧)。 I really need to make this work, and the fact is that the same thing happen whenever I try to use tools:something. 我确实需要完成这项工作,事实是,每当我尝试使用tools:something时,都会发生相同的事情。 在此处输入图片说明

I'm using Android Studio 1.4 Edit : I tried to clone a project that where using tools AND data binding, and the preview works! 我正在使用Android Studio 1.4 Edit:我试图克隆一个项目,在该项目中使用工具和数据绑定以及预览可以正常工作!

Hello I had checked again the UI is rendring atleast for one item. 您好,我再次检查了UI是否至少有一项。 In my it is giving "Rendering Problems onLayout error" while rendering but shows one row item. 在我看来,它在渲染时给出“ Rendering Problems onLayout错误”,但显示了一行项目。 To make it possible you have to make few changes in xml code: 为了使之成为可能,您必须在xml代码中进行一些更改:

    <ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/listView2"
    tools:listitem="@layout/item_chat"/>

make sure you are using latest build version tools. 确保您使用的是最新的构建版本工具。 I have checked with following: 我检查了以下内容:

    buildToolsVersion "23.0.0"
    classpath 'com.android.tools.build:gradle:1.3.0'
    classpath "com.android.databinding:dataBinder:1.0-rc1"

If it still gives try with latest build tools from SDK manager. 如果仍然可以尝试使用SDK Manager提供的最新构建工具。 I have install following plugin in addition: 我还安装了以下插件:

Android SDK platform-tools version 23.1 rc1 under Tools(Preview channel) 工具下的Android SDK平台工具版本23.1 rc1(预览频道)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM