Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android layouts overview #62

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,66 @@ Examples of specific strings:
<dimen name="large_padding">24dp</dimen>
<dimen name="xlarge_padding">32dp</dimen>
```

### 6. Layouts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please include the default config for Studio's formatter.


* Always to keep 4 spaces of indentation between levels.
* Prevent double indentation between element name and first property
rkowalski4 marked this conversation as resolved.
Show resolved Hide resolved
(which is a default behaviour of android studio)
rkowalski4 marked this conversation as resolved.
Show resolved Hide resolved
* Place `android:id` at the first position.
* Place `style` after `android:id`.
* Place `android:layout_width` and `android:layout_height` after `style`.
* Try to keep similar order of properties in different layout's element.
rkowalski4 marked this conversation as resolved.
Show resolved Hide resolved
* Always use resources for values such as dimens, strings or colors.


Example of well formatted xml:
```xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true">

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/unit_3"
android:layout_marginTop="@dimen/unit_2"
android:layout_marginEnd="@dimen/unit_3"
android:layout_marginBottom="@dimen/unit_1">

<TextView
android:id="@+id/title"
style="@style/H5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/teal_blue"
android:layout_marginStart="@dimen/unit_3"/>

<ImageView
android:layout_width="@dimen/unit_3"
android:layout_height="@dimen/unit_3"
android:src="@mipmap/ic_arrow_right"
android:padding="@dimen/unit_05"
android:layout_alignParentEnd="true"
android:layout_marginEnd="@dimen/unit_1"/>

<View
style="@style/underline"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_below="@+id/title"/>

</RelativeLayout>

</FrameLayout>
```

Android Studio provides a feature that allows you automatically sort and
reformat layout. Just use a shortcut `Shift + Ctrl + l`. It works quite well
and can be helpful during development process, but you have to pay
attention to be sure, it respects rules above.
rkowalski4 marked this conversation as resolved.
Show resolved Hide resolved