List
Convert the List design to iOS/Android code.
If you need to display scrolling elements dynamically, you should check if they are lists or grids. Lists are vertical, and grids can be vertical or horizontal. In lists, only 1 cell can be in a column but for Grids, it can be more than 1 cell in a column. Here is an example of both of them:
Lists and Grids
This page is created for lists.
If you need to display scrolling elements dynamically, you should check if they are lists or grids. You can find how to understand the difference here. If you have decided that you want to create lists, this is the right place to read.
An example of a list is below. In the image, the cell prototype repeats itself with different data inside.
Lists are called different names in iOS and Android. They are explained below with the code and details.
List Example.
List creation GIF.

Generated code for iOS/Android and Details

iOS
Android

TableView

Lists are called inTableView Swift language. With TableView, you can view a group that aligns all children in a single direction. InTableView, no matter how wide they are, the vertical list has only one child per row, and your list will only be the one-row height(Height of the tallest child + padding).
CellPrototypewraps a layout and will often be the container used in a layout for each item within a TableView. Let's check the generated code.
TableView is added to the page's View Controller file.
ListPageViewController.swift
1
import UIKit
2
​
3
class ListPageViewController: UIViewController {
4
​
5
//Connection from an Interface Builder to a UI component
6
@IBOutlet private weak var explorePostsTableView: UITableView!
7
​
8
override func viewDidLoad() {
9
super.viewDidLoad()
10
setupViews()
11
}
12
}
13
​
14
extension ListPageViewController {
15
private func setupViews() {
16
17
//TableView properties
18
self.explorePostsTableView.rowHeight = UITableView.automaticDimension
19
self.explorePostsTableView.estimatedRowHeight = 30
20
self.explorePostsTableView.dataSource = self
21
​
22
}
23
24
}
25
​
26
// MARK: - Table View DataSource
27
​
28
extension ListPageViewController: UITableViewDataSource {
29
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
30
return 1
31
}
32
​
33
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
34
let cell = tableView.dequeueReusableCell(withIdentifier: "ExplorePostTableViewCell") as! ExplorePostTableViewCell
35
return cell
36
}
37
}
Copied!
The Cell is added as a separate file.
ExplorePostsTableViewCell.swift
1
​
2
import UIKit
3
import SnapKit
4
​
5
class ExplorePost: UITableViewCell {
6
7
// MARK: - Properties
8
@IBOutlet private weak var photoImageView2: UIImageView!
9
@IBOutlet private weak var rosieDelLabel: UILabel!
10
@IBOutlet private weak var likesLabel: UILabel!
11
@IBOutlet private weak var heartLikedImageView: UIImageView!
12
​
13
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
14
super.init(style: style, reuseIdentifier: reuseIdentifier)
15
self.setupViews()
16
}
17
​
18
required init?(coder aDecoder: NSCoder) {
19
super.init(coder: aDecoder)
20
}
21
​
22
func setupViews() {
23
24
rosieDelLabel.text = NSLocalizedString("rosie.del", comment: "")
25
rosieDelLabel.textColor = UIColor.porpoise
26
rosieDelLabel.numberOfLines = 0
27
rosieDelLabel.font = UIFont.textStyle2
28
rosieDelLabel.textAlignment = .left
29
​
30
likesLabel.text = NSLocalizedString(".likes2", comment: "")
31
likesLabel.textColor = UIColor.anchor2
32
likesLabel.numberOfLines = 0
33
likesLabel.font = UIFont.textStyle6
34
likesLabel.textAlignment = .right
35
​
36
}
37
}
Copied!

RecyclerView-LinearLayoutManager

⚠️This feature is available in only Mac App. Web App support for Android is coming soon. If you need to install the desktop app, click here.​
In Android lists are used with RecyclerViewandLinearLayout. The repetitive cells are CardView
With LinearLayout, you can view a group that aligns all children in a single direction. InLinearLayout, no matter how wide they are, the vertical list has only one child per row, and your list will only be the one-row height(Height of the tallest child + padding).
Android RecyclerView and CardView
CardView wraps a layout and will often be the container used in a layout for each item within a RecyclerView. Let's check the generated code.
1
<!--activityListPage.xml-->
2
<androidx.recyclerview.widget.RecyclerView
3
android:id="@+id/explorePicturesRecyclerView"
4
android:layout_width="0dp"
5
android:layout_height="0dp"
6
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
7
tools:listitem="@layout/layout_explore_post_card_view"
8
android:layout_marginStart="20dp"
9
android:layout_marginEnd="19dp"
10
app:layout_constraintStart_toStartOf="parent"
11
app:layout_constraintEnd_toEndOf="parent"
12
app:layout_constraintTop_toBottomOf="@+id/popularTextView"
13
app:layout_constraintBottom_toBottomOf="parent"/>
Copied!
1
<!--LayoutExplorePhotoCardView.xml-->
2
<androidx.cardview.widget.CardView
3
xmlns:android="http://schemas.android.com/apk/res/android"
4
xmlns:app="http://schemas.android.com/apk/res-auto"
5
xmlns:tools="http://schemas.android.com/tools"
6
android:layout_width="match_parent"
7
android:layout_height="wrap_content">
8
9
<androidx.constraintlayout.widget.ConstraintLayout
10
android:layout_width="match_parent"
11
android:layout_height="wrap_content">
12
13
<ImageView
14
android:id="@+id/photoImageView"
15
android:layout_width="0dp"
16
android:layout_height="wrap_content"
17
android:src="@drawable/photo"
18
android:scaleType="centerCrop"
19
android:layout_marginEnd="0dp"
20
android:layout_marginBottom="13dp"
21
app:layout_constraintStart_toStartOf="parent"
22
app:layout_constraintEnd_toEndOf="parent"
23
app:layout_constraintTop_toTopOf="parent"
24
app:layout_constraintBottom_toTopOf="@+id/rosieDelTextView"/>
25
26
<TextView
27
android:id="@+id/rosieDelTextView"
28
android:layout_width="0dp"
29
android:layout_height="wrap_content"
30
android:text="@string/rosie_del"
31
style="@style/textStyle2"
32
android:textAlignment="textStart"
33
android:textColor="?attr/porpoise"
34
android:layout_marginEnd="8dp"
35
app:layout_constraintStart_toStartOf="parent"
36
app:layout_constraintEnd_toStartOf="@+id/likesTextView"
37
app:layout_constraintTop_toBottomOf="@+id/photoImageView"
38
app:layout_constraintBottom_toBottomOf="parent"/>
39
40
<TextView
41
android:id="@+id/likesTextView"
42
android:layout_width="wrap_content"
43
android:layout_height="wrap_content"
44
android:text="@string/_likes"
45
style="@style/textStyle6"
46
android:textAlignment="textEnd"
47
android:textColor="?attr/anchor2"
48
android:layout_marginEnd="8dp"
49
android:layout_marginTop="13dp"
50
app:layout_constraintStart_toEndOf="@+id/rosieDelTextView"
51
app:layout_constraintEnd_toStartOf="@+id/heartLikedImageView"
52
app:layout_constraintTop_toBottomOf="@+id/photoImageView"
53
app:layout_constraintBottom_toBottomOf="parent"/>
54
55
<ImageView
56
android:id="@+id/heartLikedImageView"
57
android:layout_width="wrap_content"
58
android:layout_height="wrap_content"
59
android:src="@drawable/heartliked"
60
android:layout_marginTop="14dp"
61
android:layout_marginBottom="1dp"
62
app:layout_constraintStart_toEndOf="@+id/likesTextView"
63
app:layout_constraintEnd_toEndOf="parent"
64
app:layout_constraintTop_toBottomOf="@+id/photoImageView"
65
app:layout_constraintBottom_toBottomOf="parent"/>
66
67
</androidx.constraintlayout.widget.ConstraintLayout>
68
</androidx.cardview.widget.CardView>
Copied!
Last modified 11mo ago