Android Studio Beta 1.2 issue formatting xml-layout - android

Recently I’ve upgraded from Android Studio 1 to Android Studio Beta 1.2.
And among other issues, it seems that the shortcut (Option + Command + L) for formatting the xml-layouts it doesn’t reorganice code any more.
In the previous version of Android Studio, if you had something like this:
<RelativeLayout
android:layout_alignParentLeft="true"
android:layout_margin="#dimen/_10dp"
android:id="#+id/rl_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
After formatting you got the next result:
<RelativeLayout
android:id="#+id/rl_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="#dimen/_10dp">
But now I just get this message: “No lines changed. Code is already properly formatted”
Is there any kind of configuration that I’m missing it?
Thanks!

Try Ctrl+Shift+Alt+L, you should have a dialog where you can tick "Rearrange".

Related

Android Lint not detect UnusedAttribute

In an empty project(create from new project),Android Studio can not detect lint issue "UnusedAttribute", neither code editor display hint or run Ananlyze manually(the item is checked).
And there is no lint.xml or lint config in build.gradle file in project.
android studio screenshot
my code is
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Hello World!"
android:paddingHorizontal="52dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:paddingHorizontal is introduced in version 26, and my minSdkVersion is 16.
Also, command line
./gradlew :app:lintDebug
output:lint-results-debug.html also show no detect "UnusedAttribute" problem.
I think it is my env or ide problem, but do not know what is it.
Anyone have this problem?
Additional information:
I want a clean project to figure out this problem and create empty project. In my production project Android studio also can not detect android:paddingHorizontal issue, but can detect android:networkSecurityConfig, and command line output is here:
lint-results-debug.html screenshot

Constraint layout can not be rendered in Android studio

Coding a constraint layout:
<View
android:id="#+id/divider"
style="#style/divider_style"
android:layout_width="0dp"
swedbank:layout_constraintBottom_toBottomOf="parent"
swedbank:layout_constraintLeft_toLeftOf="parent" />
<ImageView
android:id="#+id/some_image"
style="#style/some_style"
swedbank:layout_constraintBottom_toBottomOf="#+id/divider" <!-- This '+' -->
swedbank:layout_constraintRight_toRightOf="parent"
swedbank:layout_constraintTop_toTopOf="#+id/divider" /> <!-- This '+' -->
See the comments: the plusses on those lines must be there for the android studio layout renderer to work. without them you get:
Couldn't resolve resource #id/divider Tip: Try to refresh the layout.
I always thought #+id/ was for the first time you defined an id?
I've experienced IDE problems if I use +'es everywhere some years ago: With goto-definition the IDE would not know which id to go to
Tested on Android studio 2.3.3 and 3.0.1
Seeing as the auto-complete gives you plusses everywhere should i just go with that?
Try adding this to your dependencies section in the gradle
compile 'com.android.support.constraint:constraint-layout:1.0.2'

Error while adding text field in Emulator

Whenever I add any TextView in the XML file it shows me the error "Exception raised during rendering: java.lang.System.arraycopy([CI[CII)V".
What is the reasoning behind this?
This is the XML part where the above written error is being shown.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
Check the "Android version to use when rendering layouts". Chose any version that does not have "W" at the end . Those versions are for wearable devices.
This problem happened on API 20 (Android 4.4 W). Problem will be solved by changing Android version to use for rendering level form API 20 (Android 4.4 W) to API 19 (Android 4.4.2) (android icon in top right corner of graphical layout) or update your SDK to Android L (API 20 L preview)
Source of answer

XML error - Doing Google Android NDK Lesson 1

The Code:
<?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:weightSum="1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<EditText android:id="#+id/edit_message"
android:layout_weight = "1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="#string/edit_message" />
<Button
android:id="#+id/bSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button_send" />
</LinearLayout>
The error message:
BUILD FAILED
C:\My First App\res\layout\activity_main.xml:7: Unexpected element "{}LinearLayout" {antlib:org.apache.tools.ant}LinearLayout
The code is almost exactly the same as the code on the Android website and it's really frustrating that I can't seem to get it to work. Is the problem in the code, or is it on my side? I am using Eclipse
I was getting the same error. I was using Indigo in Ubuntu 12.04, and no matter what libraries I got or eclipse plugins I used it was always there.
What worked for me was re-downloading and reinstalling the Android SDK (probably not necessary in your case), and downloading Eclipse Classic (Juno) from the Eclipse website rather than using the Indigo package that was in the repos. The lesson said Classic was recommended anyway, so whatever, I'm just happy it works now.
If you are using Windows, I'd still suggest downloading the most recent Classic version, but otherwise I can't be of help there.

New line (\n) in Android XML. Android 4.1 SDK Compatibility issue?

I faced this strange problem.
On my layout xml, I have a single TextView, and in it I have the following text:
"Welcome to App.\n etc" , defined in strings.xml.
In a tablet running 4.0 displays the full string.
In a smartphone running 2.3.7 it displays just before the \n.
On previous apps I have created, \n worked okay.
Anybody faced something similar?
XML Code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textViewWelcomeNotes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="false"
android:layout_centerHorizontal="true"
android:layout_centerVertical="false"
android:layout_margin="15dp"
android:layout_marginTop="20dp"
android:fitsSystemWindows="false"
android:focusableInTouchMode="true"
android:gravity="center_vertical|center_horizontal"
android:hint="#string/msgWelcomeNotesHint"
android:paddingTop="10dp"
android:text="#string/msgWelcomeNotes"
android:textSize="14dp" />
</RelativeLayout>
It was a weird bug of latest ADT 20.0, in Eclipse Juno.
I made a fresh install of Eclipse Juno, because i heavily loaded it with plugins,
and now \n appears okay, in the same apk, on 2.3 and 4.0+ Android Versions.
Also some other bugs, eg when creating new activity (New->Other->Android Activity), exist on this ADT.

Categories

Resources