Skip to content

Commit

Permalink
Add section on XML layouts #38
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafał Kowalski committed Aug 5, 2019
1 parent bb521eb commit 5272424
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions kotlin.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,61 @@ Examples of specific strings:
<dimen name="large_padding">24dp</dimen>
<dimen name="xlarge_padding">32dp</dimen>
```

### 6. Layouts

* Always to keep 4 spaces of indentation between levels.
* Prevent double indentation between element name and first property
(which is a default behaviour of android studio)
* 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.
* 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>
```

0 comments on commit 5272424

Please sign in to comment.