How to apply TAB on several lines in Android Studio - android

I am wondering if there is a shortcode (MAC) to tab several lines (see example below).
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Name"
android:id="#+id/textView"
android:layout_column="0"
android:layout_weight="1"/>
->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Last Name"
android:id="#+id/textView"
android:layout_column="0"
android:layout_weight="1"/>
I looked through the command list, but couldn`t find something. Maybe there is another way to do so.

Sure. Press (and keep pressed) the alt-option command on your Mac, then click with the mouse/touchpad and move upwards/downwards. The effect is the following:
(source)

Select several lines, then press tab to indent them or press Shift + tab to unindent them. This works at least on OS X V10.11.6 with Android Studio V2.1.2. Hope this helps you or people who read this question. Thanks.

To tab shift multiple lines in android studio editor:
Select lines ( SHIFT-DOWN/UP ) and press TAB key
Shift TAB does the same backwards.

You can try with CMD+Shift+L (auto indent)

Related

Android Studio 2.3.1 Button not positioned correctly in emulator or actual device

I selected the simple "Hello World" template added a button "Calculate".
However the image that displays in the emulator and in an actual device does not center the button but instead positions it in the top left corner.
The generated XML shows x, y positioning
<Button
android:id="#+id/Calculate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calculate"
android:textAppearance="#style/TextAppearance.AppCompat.Display1"
tools:layout_editor_absoluteX="109dp"
tools:layout_editor_absoluteY="326dp" />
Ran Lint and it suggested the emulator/actual view would display differently if there were not layout constraints so I copied the ones from the "Hello World" into the Button and things worked correctly from there on.
<Button
android:id="#+id/Calculate"
android:layout_width="154dp"
android:layout_height="57dp"
android:text="Calculate"
android:textAppearance="#style/TextAppearance.AppCompat.Display1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintHorizontal_bias="0.224"
app:layout_constraintVertical_bias="0.938"
/>
Maybe the Design/editor should add them as a default if they needed?
If you are not trying to do anything too extensive with positioning objects, go to the "Component Tree" menu > "Constraint Layout" > "Infer Constraints". This will automatically align objects where you position them in the Design terminal and should display correctly on your emulator.
*This helped me, using Android 2.3.

Is it possible to force Android Studio to display all XML elements' properties on the properties pane?

I am learning to use Android Studio 2.2. It is annoying to find that many XML elements' properties are not displayed on the properties pane. There must be a way to force AS to display them all.
For example:
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_margin="#dimen/activity_vertical_margin"
android:text="text text text"
android:id="#+id/editText"
tools:ignore="LabelFor"
android:textAlignment="viewStart" />
Corresponding properties pane:
screenshot of properties pane
Notice that layout_weight is missing from the pane. I remember the old version of AS used to display them all.
Use the icon above the properties pane depicting two opposite facing arrows to toggle between the new and old properties pane.

TextView in all projects moved to the right

This is easily the weirdest problem I've ever faced.
So today, I created a new Android Project. The first layout xml had just a textview that has the following properties (its inside a relative layout):
<TextView
android:id="#+id/textView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="124dp"
android:background="#80ffffff"
android:gravity="center_vertical"
android:text="Welcome"
android:textSize="48dp"
android:textStyle="bold" />
What I wanted was to have a textview that has text in its center. But the text STARTS from the center and goes out of screen towers the right side.
So I thought I must be doing something wrong. I went into one of my older projects (it was also open in eclipse). I opened an XML there, and shockingly, all the text there has also moved to the left (It starts from the center, rather than actually centering the text). It was fine yesterday. Here's the button:
<Button
android:id="#+id/gettingstarted"
android:layout_width="210dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/login"
android:layout_below="#+id/login"
android:layout_marginTop="10dp"
android:text="Getting Started"
android:textColor="#ffffff" />
I have no idea what happened. Why is the text no longer centered in buttons in all my projects? I'm in a really tough spot right now. Kindly help.
For your first problem try
android:gravity="center_vertical|center"
but for your text views in your all projects , it's a general question , maybe it's occured because of changing in your apps theme or projects styles

Code changes in Android's layout XML

I have a problem where my code automatically changes while I'm clicking or moving the cursor somewhere. This happens in a layout XML.
I use Eclipse Juno and I inserted an ExpandableList. My min sdk is 14 and max is 16.
It seems though that only the .xml part changes and not the layout. The .xml part, if opened again, is ok, but it does the same thing.
Helpz?
EDIT
I also noticed that the expandable list does not show up when I run the code(it just calls the layout)
The XML file:
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ExpandableListView
android:id="#+id/expandableListView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1" >
</ExpandableListView>
Do you mean the code visually changes to other lines of code already in your XML file? Eclipse does this to me every now and then. Not sure why (I'm guessing it might be a bug with Lint) but usually closing and re-opening Eclipse fixes it for me.
From what I remember the code actually isn't changing, just what's being displayed.
try to align the code using ctrl + shift + f, and if the problem stod, reopen the xml file, and at last try to close eclipse and open it again.

How to format Android xml in Eclipse?

The GUI designer for Android in Eclipse spits out this type of XML (into a layout):
<Button android:layout_height="wrap_content" android:id="#+id/btnSaveMessage" android:layout_width="wrap_content" android:layout_gravity="right" android:text="#string/text_save" android:width="125dp"></Button>
Is there a refactoring in Eclipse to turn this goo into pretty formatted XML like this:
<Button android:layout_height="wrap_content"
android:id="#+id/btnSaveMessage"
android:layout_width="wrap_content"
android:layout_gravity="right"
android:text="#string/text_save"
android:width="125dp"/>
Press ctrl + shift + F
or
Press ctrl + I
Yes you can do this.
For doing so follow the steps
Select the source code in xml file.
Right click on selected source code.
Now go the Source->cleanup document.
Now a cleanup window is popup, mark check for appropriate options and click ok.
you can also choose source->format to do some formatting in xml. cleanup provide some other fuctionalites besides format.

Categories

Resources