Created
October 18, 2019 20:12
-
-
Save CodeNextPaco/f014a9feb4adb5fa436d5153cc860e90 to your computer and use it in GitHub Desktop.
View method challenges
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<androidx.constraintlayout.widget.ConstraintLayout 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" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
tools:context=".MainActivity"> | |
<TextView | |
android:id="@+id/textView" | |
android:layout_width="wrap_content" | |
android:layout_height="50dp" | |
android:text="Hello World!" | |
android:onClick="grow" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintLeft_toLeftOf="parent" | |
app:layout_constraintRight_toRightOf="parent" | |
app:layout_constraintTop_toBottomOf="@+id/imgView" | |
app:layout_constraintVertical_bias="0.317" /> | |
<ImageView | |
android:id="@+id/imgView" | |
android:layout_width="189dp" | |
android:layout_height="195dp" | |
android:layout_marginTop="64dp" | |
android:onClick="hideOrShow" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toTopOf="parent" | |
app:srcCompat="@mipmap/ic_launcher_round" /> | |
<Button | |
android:id="@+id/button" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:text="Button" | |
android:onClick="shrink" | |
app:layout_constraintBottom_toBottomOf="parent" | |
app:layout_constraintEnd_toEndOf="parent" | |
app:layout_constraintHorizontal_bias="0.498" | |
app:layout_constraintStart_toStartOf="parent" | |
app:layout_constraintTop_toBottomOf="@+id/textView" | |
app:layout_constraintVertical_bias="0.166" /> | |
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//your project namer may differ | |
//package com.example.methodpractice; | |
import androidx.appcompat.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
public class MainActivity extends AppCompatActivity { | |
private Button myButton; | |
private ImageView myImage; | |
private TextView myText; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
myButton = findViewById(R.id.button); //these should match the xml id | |
myImage = findViewById(R.id.imgView); | |
myText = findViewById(R.id.textView); | |
} | |
/* The first 3 methods below are called in the XML of the views */ | |
public void grow(View v){ | |
//make the view grow, increase height and width | |
v.animate().scaleX(1.3f).scaleY(1.3f).setDuration(600).start(); //change me! | |
Log.d("views", "growing"); | |
} | |
public void shrink(View v){ | |
//make it shrink using above example | |
Log.d("views", "shrinking"); | |
} | |
public void hideOrShow(View v){ | |
Log.d("views", "hiding or showing"); | |
//make a function that hides the view if visible, and shows if hidden | |
} | |
public void changeText(View v){ | |
//test with button and text view | |
} | |
public String getViewID(View v){ | |
String id = "an id"; //change | |
return id; | |
} | |
public void goCrazy(){ | |
//use the animate example above to make other animations! | |
//or look here: https://codinginfinite.com/basic-android-animation-example/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment