EDIT : this issue now only happens when I try to have a listview with a preview layout that contains databinding (from android databinding)
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.
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. I checked that the listview has an id (and all the solutions I found on stackoverflow) but nothing works. 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.
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!
Hello I had checked again the UI is rendring atleast for one item. In my it is giving "Rendering Problems onLayout error" while rendering but shows one row item. To make it possible you have to make few changes in xml code:
<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. I have install following plugin in addition:
Android SDK platform-tools version 23.1 rc1 under Tools(Preview channel)
Related
Can anybody how to remove this parent NavDrawer overlay showing whilst designing layout? (Screen 1).
The overlay is removed when running in actual device (Screen 2).
Because of this I can't design child elements right there in the studio.
Any help would be great!
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Always Visible."
/>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
When you see that gray block with the tag name in it, that means that Android Studio can't resolve the class from the tag in your layout, so it doesn't know what to preview. Often this will happen if you have a typo in your layout file, but then you wouldn't see it working when you actually run the app.
For me, I can make this happen quite easily by using the old support library versions of widgets, since I have AndroidX enabled in my project. For example, just pasting your code in to my IDE gives me the same gray box, but changing your tags to use AndroidX fixes it (android.support.v4.widget.DrawerLayout -> androidx.drawerlayout.widget.DrawerLayout).
Chances are good that your Android Studio just needs a kick in the pants.
I suggest doing a Gradle Sync (File -> Sync Project with Gradle Files) and, if that doesn't work, an Invalidate + Restart (File -> Invalidate Caches / Restart...).
I am a beginner in android development. I have created a android project. But in the preview section, I am not able to see the components. But components are visible when i run the same app on emulator i am able to see the components. I am missing some setting here? XML is given below.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
I've had have also this problem and solved it by only selecting another "Theme" cause
the default theme appTheme doesn't show added items.
If you i.e. select Transulcent, any item becomes visible ;-)
cheers
Oliwan
Maybe sound a weird answer, but self-tested this.
Change the XML file's (maybe activity_x.xml) layout's root tag android.support.constraint.ConstraintLayout to LinearLayout, then preview will start working again (as happened in my case). [If not, then perform force refresh (R)]
Then switch back to old one, I mean: Change the XML file's (maybe activity_x.xml) layout's root tag LinearLayout to android.support.constraint.ConstraintLayout. And force a refresh.
This does seem to be a bug in Android Studio. When it showed up for me, I fixed it by making a trivial change in the app build.gradle (change version code), do a gradle sync, then change back and sync again.
After that, the design view worked again.
I have installed all sdk and correctly installed but I have tried multiple times but I cannot fine frame of app where I can insert tool,widgets, button, etc. (Cannot add anything on workspace)
My Android studio window image: https://drive.google.com/file/d/0B8AWJ5JO_e0xVV9KVEE0TUpMYWc/view?usp=drivesdk
Select devices,sdk and theme,like this
image: https://drive.google.com/open?id=0B7VdJKtF9NwGNVFKeE5zZ2pxVHM
Looks like you've gotten rid of the Component Tree.
Try go to the Text-tab and paste
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
or whatever root layout you need...
My issue is similar to this but Android Studio doesn't tell me anything about a rendering issue or compiler/build errors(I was able to build fine).
Here is what I am seeing(this is a new project)
And the contents of content_main.xml
After reading on different rendering issue threads, I I've tried rebuilding, cleaning, invalidate caches/restart and even starting a new project to see if the layout preview was working(Still empty)
I also played around with different sdk versions(20,19) to see if the layout preview was working but all I got was this quirky issue that I don't think would cause the layout preview to not work.
Does anyone know what my problem is here? I didn't mess around with my initial Gradle files and remove any support library dependencies. Another solution I had in mind was reinstalling Android Studio but that's last resort.
Just check your sdk valid version like example.
Try putting your TextView element into an empty FrameLayout:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/my_groups" />
</FrameLayout>
This code above should be put inside your RelativeLayout. Hope it helps.
Just recently, my Android XML files which define my layout and etc have stopped autocompleting. When I type android: I used to get a list of options related to Android such as layout_width, etc. Now I get only four options, the first being xmlns="default namespace"
Also the tab to change to the layout designer and other tabs are gone, I am left with a 'design' tab which shows my XML structure and a 'source' tab with the actual XML. I think they are being recognised as normal XML files rather than Android XML files, is there a way to change this?
I am running Eclipse Indigo Version 3.7.0 with the ADT plugin Version 15.0.1.
Here is an example of one of the XML files it isn't working in:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16dp"
android:background="#FFFFFF"
android:textColor="#000000" ></TextView>
Switch to a new workspace may help.