Skip to content

Commit

Permalink
feat(animation): animation implemented with ScrollView
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrucesdeveloper committed Aug 16, 2022
1 parent 5cdf520 commit 489c025
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@

import android.animation.ObjectAnimator;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

Expand All @@ -22,6 +24,8 @@
import com.jorgecruces.metrometro.model.Metro;
import com.jorgecruces.metrometro.model.Station;

import org.w3c.dom.Text;

import java.util.ArrayList;
import java.util.Collections;

Expand Down Expand Up @@ -51,31 +55,50 @@ protected void onCreate(Bundle savedInstanceState) {
}

private void testMethod() {
LinearLayout linearLayout = findViewById(R.id.gameLayout);
RelativeLayout linearLayout = findViewById(R.id.gameLayout);
TextView textView = new TextView(this);
textView.setText("HOLa");
textView.setId(View.generateViewId());
linearLayout.addView(textView);

RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);

Resources r = this.getResources();
int px = (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
285,
r.getDisplayMetrics()
);

layoutParams.setMarginStart(px);

StationView stationView = new StationView(this);
stationView.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
));
stationView.setLayoutParams(layoutParams);
linearLayout.addView(stationView);


StationView stationView2 = new StationView(this);
stationView2.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
));
stationView2.setId(View.generateViewId());

RelativeLayout.LayoutParams layoutParams2 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
layoutParams2.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);

stationView2.setLayoutParams(layoutParams2);
linearLayout.addView(stationView2);

DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int height = displayMetrics.heightPixels;
int width = displayMetrics.widthPixels;

// ObjectAnimator animation = ObjectAnimator.ofFloat(stationView, "translationX", -(width/2));
// animation.setDuration(3000);
// animation.start();

stationView.animate().translationX(-1000f).setDuration(3000);

}

Expand Down
25 changes: 25 additions & 0 deletions app/src/main/res/drawable/ic_mediamodifier_design_2_.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="1080dp"
android:height="1080dp"
android:viewportWidth="1080"
android:viewportHeight="1080">
<path
android:pathData="M0,0h1080v1080h-1080z"/>

<path
android:pathData="M0,0h1080v1080h-1080z"
android:strokeLineJoin="miter"
android:strokeWidth="1"
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:strokeColor="#00000000"
android:strokeLineCap="butt"/>
<path
android:pathData="M378.38,108.53l1101.73,0l0,777.5l-1101.73,0z"
android:strokeLineJoin="miter"
android:strokeWidth="0"
android:fillColor="#FF0101"
android:fillType="nonZero"
android:strokeColor="#000000"
android:strokeLineCap="butt"/>
</vector>
25 changes: 25 additions & 0 deletions app/src/main/res/drawable/ic_mediamodifier_design_5_.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="1080dp"
android:height="1080dp"
android:viewportWidth="1080"
android:viewportHeight="1080">
<path
android:pathData="M0,0h1080v1080h-1080z"
/>
<path
android:pathData="M0,0h1080v1080h-1080z"
android:strokeLineJoin="miter"
android:strokeWidth="1"
android:fillColor="#FFFFFF"
android:fillType="nonZero"
android:strokeColor="#00000000"
android:strokeLineCap="butt"/>
<path
android:pathData="M-390.87,-122.37l1788.58,0l0,1262.52l-1788.58,0z"
android:strokeLineJoin="miter"
android:strokeWidth="0"
android:fillColor="#FF0101"
android:fillType="nonZero"
android:strokeColor="#000000"
android:strokeLineCap="butt"/>
</vector>
32 changes: 19 additions & 13 deletions app/src/main/res/layout/activity_play_game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="180dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="181dp"
android:layout_marginBottom="8dp"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/textViewAlternative1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/gameLayout">
app:layout_constraintStart_toStartOf="parent">

<TextView
android:id="@+id/textViewCurrentNumberQuestion"
Expand Down Expand Up @@ -124,21 +124,27 @@
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/textViewAlternative1" />

<LinearLayout
android:id="@+id/gameLayout"
<HorizontalScrollView
android:layout_width="0dp"
android:layout_height="300dp"
android:layout_marginTop="8dp"
android:background="@android:drawable/edit_text"
android:gravity="clip_horizontal|clip_vertical|center_horizontal|center_vertical"
android:orientation="horizontal"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/linearLayout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewTitle"
app:layout_constraintTop_toBottomOf="@+id/textViewTitle">

>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >

</LinearLayout>
<RelativeLayout
android:id="@+id/gameLayout"
android:layout_width="wrap_content"
android:layout_height="match_parent">

</RelativeLayout>
</LinearLayout>
</HorizontalScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>
43 changes: 31 additions & 12 deletions app/src/main/res/layout/station_layout.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:gravity="center_horizontal|center_vertical"
android:layout_centerVertical="true"
android:animateLayoutChanges="true"
android:gravity="start|center_horizontal|center_vertical"
android:orientation="vertical">

<RelativeLayout
Expand All @@ -12,27 +15,43 @@
android:layout_weight="1">

<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:id="@+id/imageView8"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_centerInParent="true"
android:backgroundTint="#FF0000"
android:layout_marginStart="-10dp"
app:srcCompat="@drawable/metro_svg" />

<ImageView
android:id="@+id/imageView3"
android:layout_width="match_parent"
android:id="@+id/imageView9"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerInParent="true"
app:srcCompat="@drawable/ic_baseline_circle_24" />
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
app:srcCompat="@drawable/ic_baseline_circle_24"
tools:layout_centerVertical="true" />

<ImageView
android:id="@+id/imageView10"
android:layout_width="120dp"
android:layout_height="42dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginStart="0dp"
android:layout_marginEnd="0dp"
android:layout_toEndOf="@+id/imageView9"
android:adjustViewBounds="false"
android:scaleType="centerCrop"
app:srcCompat="@drawable/ic_mediamodifier_design_5_" />
</RelativeLayout>

<TextView
android:id="@+id/textViewStationName"
android:layout_width="match_parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="30dp"
android:layout_weight="1"
android:text="TextView"
android:textAlignment="center" />
android:textAlignment="viewStart" />

</LinearLayout>

0 comments on commit 489c025

Please sign in to comment.