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

Added MotionLayout for transition animation #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class NewsActivity : BaseActivity() {

val adapter = NewsArticlesAdapter { toast("Clicked on item") }
newsList.adapter = adapter
newsList.layoutManager = LinearLayoutManager(this)

// Update the UI on state change
newsArticleViewModel.getNewsArticles().observeNotNull(this) { state ->
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
android:id="@+id/newsList"
android:layout_width="0dp"
android:layout_height="0dp"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
Expand Down
90 changes: 50 additions & 40 deletions app/src/main/res/layout/row_news_article.xml
Original file line number Diff line number Diff line change
@@ -1,60 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.motion.widget.MotionLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
style="@style/NewsArticle.View"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="@dimen/card_elevation">
app:layoutDescription="@xml/row_news_article_scene">

<RelativeLayout
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
style="@style/NewsArticle.View"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/drawable_list_item">
app:cardElevation="@dimen/card_elevation"
app:layout_constraintTop_toTopOf="parent">

<!-- News block -->
<RelativeLayout
android:id="@+id/newsImageView"
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="180sp">
android:layout_height="wrap_content"
android:background="@drawable/drawable_list_item">

<ImageView
android:id="@+id/newsImage"
style="@style/NewsArticle.Image"
<!-- News block -->
<RelativeLayout
android:id="@+id/newsImageView"
android:layout_width="match_parent"
android:layout_height="@dimen/image_size"
android:contentDescription="@string/news_image"
tools:src="@drawable/tools_placeholder" />
android:layout_height="180sp">

<ImageView
android:id="@+id/newsImage"
style="@style/NewsArticle.Image"
android:layout_width="match_parent"
android:layout_height="@dimen/image_size"
android:contentDescription="@string/news_image"
tools:src="@drawable/tools_placeholder" />

<TextView
android:id="@+id/newsAuthor"
style="@style/NewsArticle.Author"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
tools:text="ABC News" />

</RelativeLayout>

<!-- News Title -->
<TextView
android:id="@+id/newsAuthor"
style="@style/NewsArticle.Author"
android:id="@+id/newsTitle"
style="@style/NewsArticle.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
tools:text="ABC News" />
android:layout_below="@+id/newsImageView"
tools:text="Elon Musk says Tesla can't yet launch in India" />

</RelativeLayout>
<!-- Publish at -->
<TextView
android:id="@+id/newsPublishedAt"
style="@style/NewsArticle.PublishedAt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/newsTitle"
android:layout_marginStart="@dimen/normal_padding"
android:layout_marginLeft="@dimen/normal_padding"
tools:text="@string/str_test_date" />

<!-- News Title -->
<TextView
android:id="@+id/newsTitle"
style="@style/NewsArticle.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/newsImageView"
tools:text="Elon Musk says Tesla can't yet launch in India" />

<!-- Publish at -->
<TextView
android:id="@+id/newsPublishedAt"
style="@style/NewsArticle.PublishedAt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/newsTitle"
android:layout_marginStart="@dimen/normal_padding"
android:layout_marginLeft="@dimen/normal_padding"
tools:text="@string/str_test_date" />
</RelativeLayout>
</androidx.cardview.widget.CardView>

</RelativeLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.motion.widget.MotionLayout>
26 changes: 26 additions & 0 deletions app/src/main/res/xml/row_news_article_scene.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<MotionScene xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<ConstraintSet android:id="@+id/start">
<Constraint android:id="@+id/widget" />
<Constraint
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="300dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</ConstraintSet>

<ConstraintSet android:id="@+id/end">
<Constraint android:id="@id/widget" />
</ConstraintSet>

<Transition
app:autoTransition="animateToEnd"
app:constraintSetEnd="@id/end"
app:constraintSetStart="@+id/start"
app:layoutDuringTransition="honorRequest" />

</MotionScene>