App bugged: ImageView doesn't appear - java

I don't understand why the app doesn't work when I launch it.
First of all, this is what I want:
Spaceship appears perfectly
And this is what appears when I launch the game:
Spaceship disappears!
I dont know what is wrong. I haven't an atribute which makes invisible the ImageView... Here is my code:
game_activity.xml (game design)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.android.spaceinvaders.GameActivity">
<ImageView
android:id="#+id/fondo_juego"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/fondo3" />
<ImageView
android:id="#+id/enemigo"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:src="#drawable/enemigodiseno11"/>
<Button
android:id="#+id/disparo"
android:layout_width="wrap_content"
android:layout_height="90dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#android:color/transparent"
android:onClick="dispara"
android:visibility="visible" />
<ImageView
android:id="#+id/municion"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/disparo"
android:layout_centerHorizontal="true"
android:src="#drawable/municion"
android:visibility="invisible" />
<ImageView
android:id="#+id/nave"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:src="#drawable/diseno11" />
<Button
android:id="#+id/control_izquierda"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#android:color/transparent"
android:onClick="actualizaPosicion"
android:visibility="visible" />
<Button
android:id="#+id/control_derecha"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#android:color/transparent"
android:onClick="actualizaPosicion"
android:visibility="visible" />
</RelativeLayout>
activity_main.xml (This is the principal screen)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/principal_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.android.spaceinvaders.MainActivity">
<ImageView
android:id="#+id/fondo_pantalla_principal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/fondo2" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:adjustViewBounds="true"
android:src="#drawable/iconotitulo"
android:layout_centerHorizontal="true"/>
<ImageView
android:layout_width="130dp"
android:layout_height="130dp"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/iconotitulo1"/>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:orientation="vertical">
<ImageButton
android:id="#+id/play_boton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:scaleType="centerCrop"
android:onClick="iniciaJuego"
android:src="#drawable/boton1" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_margin="10dp">
<ImageButton
android:id="#+id/opcion_boton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:layout_centerHorizontal="true"
android:background="#android:color/transparent"
android:scaleType="centerCrop"
android:src="#drawable/boton2" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
popup_activity.xml (a simple popup which allow the user to change some parameters)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#839ceaac"
android:orientation="vertical">
<ImageButton
android:id="#+id/volver_boton"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:layout_marginRight="2dp"
android:layout_marginTop="3dp"
android:background="#android:color/transparent"
android:scaleType="centerCrop"
android:src="#drawable/cerrar" />
<TextView
android:id="#+id/titulo_opciones"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="6dp"
android:layout_marginTop="5dp"
android:text="Opciones gráficas"
android:textSize="20dp"
android:textStyle="bold" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#id/titulo_opciones"
android:background="#9dc8a6" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/titulo_opciones"
android:layout_marginBottom="8dp"
android:layout_marginTop="5dp"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/fondo_titulo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:text="Fondo"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/fondo_1"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/fondo_titulo"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="actualizaFondo"
android:scaleType="centerCrop"
android:src="#drawable/fondo" />
<ImageView
android:id="#+id/fondo_2"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/fondo_1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="actualizaFondo"
android:scaleType="centerCrop"
android:src="#drawable/fondo1" />
<ImageView
android:id="#+id/fondo_3"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/fondo_2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="actualizaFondo"
android:scaleType="centerCrop"
android:src="#drawable/fondo3" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/nave_titulo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:text="Nave"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/nave_1"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/nave_titulo"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="actualizaNave"
android:src="#drawable/diseno11" />
<ImageView
android:id="#+id/nave_2"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/nave_1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="actualizaNave"
android:src="#drawable/diseno21" />
<ImageView
android:id="#+id/nave_3"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/nave_2"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="actualizaNave"
android:src="#drawable/diseno31" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<TextView
android:id="#+id/enemigos_titulo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:text="Enemigos"
android:textSize="15sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/enemigo_1"
android:layout_width="40dp"
android:layout_height="60dp"
android:layout_below="#id/enemigos_titulo"
android:layout_centerHorizontal="true"
android:layout_marginBottom="3dp"
android:adjustViewBounds="true"
android:onClick="actualizaEnemigo"
android:rotation="180"
android:src="#drawable/enemigodiseno11" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
GameActivity.java (game_activity.xml functionality)
package com.example.android.spaceinvaders;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class GameActivity extends AppCompatActivity {
ImageView municion;
ImageView nave;
ImageView fondoJuego;
ImageView enemigo;
Button botonDisparo;
Handler manejaDisparo = new Handler();
Handler manejaEnemigo = new Handler();
final int movimiento = 30;
final int movimientoEnemigo = 20;
boolean inicioAFin = false;
int ladeadoIzq, ladeadoDer, frontal, disparo;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game_activity);
municion = (ImageView) findViewById(R.id.municion);
nave = (ImageView) findViewById(R.id.nave);
enemigo = (ImageView) findViewById(R.id.enemigo);
fondoJuego = (ImageView) findViewById(R.id.fondo_juego);
botonDisparo = (Button) findViewById(R.id.disparo);
Intent i = getIntent();
if (i != null) {
String data = i.getStringExtra("arg");
introduceCambios(data);
}
manejaEnemigo.postDelayed(accionMovimiento, 0);
}
private void introduceCambios(String data) {
String[] info = data.split(" ");
int idFondo = getResources().getIdentifier(info[0], "drawable", getPackageName());
fondoJuego.setImageResource(idFondo);
int idNave = getResources().getIdentifier(info[1], "drawable", getPackageName());
cambiosMovilidad(idNave);
nave.setImageResource(frontal);
int idEnemigo = getResources().getIdentifier(info[2], "drawable", getPackageName());
enemigo.setImageResource(idEnemigo);
}
public void actualizaPosicion(View v) {
switch (v.getId()) {
case (R.id.control_derecha):
if (!seSale("der", "CU")) {
nave.setImageResource(ladeadoIzq);
nave.setX(nave.getX() - movimiento);
}
break;
case R.id.control_izquierda:
if (!seSale("izq", "CU")) {
nave.setImageResource(ladeadoDer);
nave.setX(nave.getX() + movimiento);
}
break;
}
}
private void cambiosMovilidad(int idNave) {
switch (idNave) {
case 2130837589:
frontal = R.drawable.diseno11;
ladeadoDer = R.drawable.diseno13;
ladeadoIzq = R.drawable.diseno12;
disparo = R.drawable.municion;
break;
case 2130837592:
frontal = R.drawable.diseno21;
ladeadoDer = R.drawable.diseno23;
ladeadoIzq = R.drawable.diseno22;
disparo = R.drawable.municion1;
break;
case 2130837595:
frontal = R.drawable.diseno31;
ladeadoDer = R.drawable.diseno33;
ladeadoIzq = R.drawable.diseno32;
break;
}
}
public void dispara(View v) {
nave.setImageResource(frontal);
municion.setImageResource(disparo);
municion.setX(nave.getX() + (((nave.getWidth()) / 2) - 5));
municion.setY(nave.getY());
municion.setVisibility(View.VISIBLE);
botonDisparo.setEnabled(false);
manejaDisparo.postDelayed(accionDisparo, 0);
}
Runnable accionDisparo = new Runnable() {
#Override
public void run() {
municion.setY(municion.getY() - 50);
if (llegaAlFinal()) {
municion.setVisibility(View.INVISIBLE);
manejaDisparo.removeCallbacks(accionDisparo);
botonDisparo.setEnabled(true);
}
manejaDisparo.postDelayed(this, 80);
}
};
Runnable accionMovimiento = new Runnable() {
#Override
public void run() {
if (inicioAFin) {
enemigo.setImageResource(R.drawable.enemigodiseno12);
enemigo.setX(enemigo.getX() + movimientoEnemigo);
} else {
enemigo.setImageResource(R.drawable.enemigodiseno13);
enemigo.setX(enemigo.getX() - movimientoEnemigo);
}
if (seSale("izq", "IA") || seSale("der", "IA"))
inicioAFin = !inicioAFin;
manejaEnemigo.postDelayed(this, 80);
}
};
private boolean llegaAlFinal() {
return municion.getY() <= 20;
}
private boolean seSale(String direccion, String jugador) {
switch (direccion) {
case "izq":
switch (jugador) {
case "CU":
return (nave.getX() + movimiento + nave.getWidth()) > findViewById(R.id.activity_main).getWidth();
case "IA":
return (enemigo.getX() + movimiento + enemigo.getWidth()) > findViewById(R.id.activity_main).getWidth();
}
case "der":
switch (jugador) {
case "CU":
return (nave.getX() - movimiento) < 0;
case "IA":
return (enemigo.getX() - movimiento) < 0;
}
}
return true;
}
}
MainActivity.java (activity_main.xml and popup_activity.xml functionality)
package com.example.android.spaceinvaders;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageButton;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
ImageButton opcionBoton;
private PopupWindow popup;
private RelativeLayout layoutPrincipal;
String[] resultados;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
resultados = new String[3];
resultados[0] = "fondo3";
resultados[1] = "diseno11";
resultados[2] = "enemigodiseno11";
opcionBoton = (ImageButton) findViewById(R.id.opcion_boton);
layoutPrincipal = (RelativeLayout) findViewById(R.id.principal_screen);
opcionBoton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View vistaPopup = inflater.inflate(R.layout.popup_activity, null);
popup = new PopupWindow(
vistaPopup,
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT
);
ImageButton cerrarPop = (ImageButton) vistaPopup.findViewById(R.id.volver_boton);
cerrarPop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
popup.dismiss();
opcionBoton.setVisibility(View.VISIBLE);
}
});
popup.showAtLocation(layoutPrincipal, Gravity.BOTTOM, 0, 0);
opcionBoton.setVisibility(View.INVISIBLE);
}
});
}
public void iniciaJuego(View view) {
Intent juego = new Intent(view.getContext(), GameActivity.class);
juego.putExtra("arg", resultados[0] + " " + resultados[1] + " " + resultados[2]);
startActivity(juego);
}
public void actualizaFondo(View vista) {
switch (vista.getId()) {
case R.id.fondo_1:
resultados[0] = "fondo";
break;
case R.id.fondo_2:
resultados[0] = "fondo1";
break;
case R.id.fondo_3:
resultados[0] = "fondo3";
break;
}
}
public void actualizaNave(View vista) {
switch (vista.getId()) {
case R.id.nave_1:
resultados[1] = "diseno11";
break;
case R.id.nave_2:
resultados[1] = "diseno21";
break;
case R.id.nave_3:
resultados[1] = "diseno31";
break;
}
}
public void actualizaEnemigo(View vista) {
switch (vista.getId()) {
case R.id.enemigo_1:
resultados[2] = "enemigodiseno11";
break;
}
}
}
I hope you could help me, please... I don't know where is the error.
The project repository is: github.com/cvazquezlos/Space-Invaders-Android
Thank you so much!

Related

Linear Layout grid showing in emulator but not on device, what could be cause?

I am currently running an activity that works fine on an emulator (Nexus 5X API 27), however when executing it on a device (Samsung S8 Plus); the linear layout grid does not appear. I've added the proper constraints but they still don't show.
Tried shifting the textviews to make more space for the Linear Layout grid but still no use.
A screenshot of how the activity should look like:
https://imgur.com/a/I2wEgZW
Here is the Activity Code:
import android.content.Intent;
import android.os.AsyncTask;
import android.support.v7.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;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.util.ArrayList;
public class Badges extends AppCompatActivity {
private static String TAG = "Badges.Class";
private static ImageView badge1,badge2, badge3, badge4, badge5, badge6, badge7, badge8, badge9, questionBadge;
private Button summaryButton;
public static int b1, b2, b3, b4, b5, b6, b7, b8, b9;
public static String currentUser;
public static int badgePoints;
public static TextView textPointsValue;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_badges);
//Creating Badge Icons and greying them out
badge1 = findViewById(R.id.imageBadge1);
badge2 = findViewById(R.id.imageBadge2);
badge3 = findViewById(R.id.imageBadge3);
badge4 = findViewById(R.id.imageBadge4);
badge5 = findViewById(R.id.imageBadge5);
badge6 = findViewById(R.id.imageBadge6);
badge7 = findViewById(R.id.imageBadge7);
badge8 = findViewById(R.id.imageBadge8);
badge9 = findViewById(R.id.imageBadge9);
badge1.setColorFilter(this.getResources().getColor(R.color.transparentDarken));
badge2.setColorFilter(this.getResources().getColor(R.color.transparentDarken));
badge3.setColorFilter(this.getResources().getColor(R.color.transparentDarken));
badge4.setColorFilter(this.getResources().getColor(R.color.transparentDarken));
badge5.setColorFilter(this.getResources().getColor(R.color.transparentDarken));
badge6.setColorFilter(this.getResources().getColor(R.color.transparentDarken));
badge7.setColorFilter(this.getResources().getColor(R.color.transparentDarken));
badge8.setColorFilter(this.getResources().getColor(R.color.transparentDarken));
badge9.setColorFilter(this.getResources().getColor(R.color.transparentDarken));
//Creating Summary Button
summaryButton = findViewById(R.id.summaryButtonBadge);
summaryButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(Badges.this,BadgesSummary.class);
startActivity(myIntent);
}
});
//Create Back Button
ImageView backButton = findViewById(R.id.badgeBackButton);
backButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent myIntent = new Intent(Badges.this,Home.class);
startActivity(myIntent);
}
});
//Question Mark Button
//Have yet to set up logic for this
questionBadge = findViewById(R.id.questionButBadge);
questionBadge.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//******Add Logic in here*****
}
});
//Points text
textPointsValue = findViewById(R.id.textPointsValue);
Log.d(TAG, "onCreate: the value of current user is " + currentUser);
//Staged Scenarios
if(currentUser.equals("test")){
//badge1.setColorFilter(this.getResources().getColor(R.color.transparentDarken));
Log.d(TAG, "onCreate: Ran the currentUser test method, and the value of current " +
"user " + currentUser);
badgePoints = 0;
badge1.setColorFilter(null);
addPoints(50);
b1=1;
badge2.setColorFilter(null);
addPoints(200);
b2=1;
badge3.setColorFilter(null);
addPoints(300);
b3=1;
badge4.setColorFilter(null);
addPoints(50);
b4=1;
}
else if(currentUser == "gg"){
}
else if(currentUser == "jason"){
}
//Scenario one
}
//Public method to reset the values
public static void resetBadge (){
//This resets all badges.
//Should only be ran when a new user is created.
b1 = 0;
b2 = 0;
b3 = 0;
b4 = 0;
b5 = 0;
b6 = 0;
b7 = 0;
b8 = 0;
b9 = 0;
badgePoints=0;
textPointsValue.setText(String.valueOf(badgePoints));
Log.d(TAG, "resetBadge: Badges have been reset due to new user login");
}
public static void setCurrentUser(String user){
Badges.currentUser = user;
Log.d(TAG, "setCurrentUser: User has been updated " + user);
}
public static void addPoints(int value){
badgePoints = badgePoints + value;
textPointsValue.setText(String.valueOf(badgePoints));
}
public static void achieveBadge1(){
//Create Avatar and profile
if(b1 == 0){
badge1.setColorFilter(null);
addPoints(50);
b1=1;
}
}
public static void achieveBadge2(){
//Choose major
if(b2 == 0){
badge2.setColorFilter(null);
addPoints(200);
b2=1;
}
}
public static void achieveBadge3(){
//Finish Degree
if(b3 == 0){
badge3.setColorFilter(null);
addPoints(300);
b3=1;
}
}
public static void achieveBadge4(){
//Redeem a Reward
if(b4 == 0){
badge4.setColorFilter(null);
addPoints(50);
b4=1;
}
}
public static void achieveBadge5(){
//Log in 7 days
if(b5 == 0){
badge5.setColorFilter(null);
addPoints(100);
b5=1;
}
}
public static void achieveBadge6(){
//Earn 500 points
if(b6 == 0){
badge6.setColorFilter(null);
addPoints(100);
b6=1;
}
}
public static void achieveBadge7(){
//Reviewed a Course
if(b7 == 0){
badge7.setColorFilter(null);
addPoints(200);
b7=1;
}
}
public static void achieveBadge8(){
//Saved a course
if(b8 == 0){
badge8.setColorFilter(null);
addPoints(50);
b1=1;
}
}
public static void achieveBadge9(){
//Update a wam
if(b9 == 0){
badge9.setColorFilter(null);
addPoints(100);
b9=1;
}
}
}
Here is the XML Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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=".Badges">
<ImageView
android:id="#+id/badgeBackButton"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginStart="3dp"
android:layout_marginTop="29dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/back_arrow" />
<ImageView
android:id="#+id/questionButBadge"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginTop="40dp"
android:layout_marginEnd="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/question" />
<TextView
android:id="#+id/textPointsBadge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="176dp"
android:layout_marginEnd="176dp"
android:text="Points"
android:textColor="#color/colorLightPurple"
android:textSize="18sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textPointsValue" />
<TextView
android:id="#+id/textPointsValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="176dp"
android:layout_marginEnd="177dp"
android:text="650"
android:textColor="#color/colorLightPurple"
android:textSize="35sp"
app:layout_constraintBottom_toTopOf="#+id/textPointsBadge"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/imageView13" />
<TextView
android:id="#+id/badgesText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="139dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="139dp"
android:gravity="center"
android:text="Badges"
android:textAlignment="center"
android:textColor="#color/colorLightPurple"
android:textSize="40dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="#+id/summaryButtonBadge"
android:layout_width="161dp"
android:layout_height="48dp"
android:layout_marginStart="69dp"
android:layout_marginEnd="69dp"
android:layout_marginBottom="20dp"
android:background="#drawable/purple_square_button"
android:text="See Summary"
android:textAllCaps="false"
android:textColor="#color/colorWhite"
android:textSize="17dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<LinearLayout
android:id="#+id/linIconGrid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="10dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textPointsBadge">
<LinearLayout
android:id="#+id/linTopRow"
android:layout_width="match_parent"
android:layout_height="114dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageBadge1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
app:srcCompat="#drawable/badge1" />
<ImageView
android:id="#+id/imageBadge2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
app:srcCompat="#drawable/badge2" />
<ImageView
android:id="#+id/imageBadge3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
app:srcCompat="#drawable/badge3" />
</LinearLayout>
<LinearLayout
android:id="#+id/linMidRow"
android:layout_width="match_parent"
android:layout_height="114dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageBadge4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
app:srcCompat="#drawable/badge4" />
<ImageView
android:id="#+id/imageBadge5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
app:srcCompat="#drawable/badge5" />
<ImageView
android:id="#+id/imageBadge6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
app:srcCompat="#drawable/badge6" />
</LinearLayout>
<LinearLayout
android:id="#+id/linBotRow"
android:layout_width="match_parent"
android:layout_height="114dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageBadge7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
app:srcCompat="#drawable/badge7" />
<ImageView
android:id="#+id/imageBadge8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
app:srcCompat="#drawable/badge8" />
<ImageView
android:id="#+id/imageBadge9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="5dp"
app:srcCompat="#drawable/badge9" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/imageView13"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginStart="178dp"
android:layout_marginEnd="178dp"
android:textAlignment="center"
app:layout_constraintBottom_toTopOf="#+id/textPointsValue"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/badgesText"
app:layout_constraintVertical_bias="0.0"
app:srcCompat="#drawable/onboarding2_logo2" />
</android.support.constraint.ConstraintLayout>
I think your Layout is exceeding the screen size but not scrolling. You have assigned fixed size for some the layout elements. Try enclosing the constraintLayout using a nestedScrollView.
But also note one thing:
<LinearLayout
android:id="#+id/linIconGrid"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="10dp"
android:orientation="vertical"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/textPointsBadge">
why are using match_parent for a direct child of constraintLayout? If you want to use the full width set the width as 0dp and use these
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
I found that images being used were too large (in terms of capacity e.g. 7mb each). I made the images smaller in size and everything began working fine.

Animation Problems in Android

I've got few problems in using animation in android studios:
I'm trying to translate certain images at an angle. Like in the image below I want to move that attachment pin like icons to all the ends of the corner. How can I do this?
I was trying to scale up the image of the gear image in the center every time its tapped and scale down when tapped again. However, the image starts losing its quality. How can I prevent the quality from getting deteriorated?
Here's the code:
MainActivity.java
package com.rootonelabs.vicky.pulse;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.ImageView;
import com.gigamole.library.PulseView;
public class MainActivity extends AppCompatActivity {
PulseView pulseView;
Button btnStart, btnStop;
ImageView gear;
ImageView icon1,icon2,icon3,icon4,icon5,icon6;
int chkClick = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
pulseView = (PulseView)findViewById(R.id.pv);
btnStart = (Button)findViewById(R.id.btnStart);
btnStop = (Button)findViewById(R.id.btnStop);
btnStart.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
pulseView.startPulse();
}
});
btnStop.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
pulseView.finishPulse();
}
});
gear = (ImageView)findViewById(R.id.gear);
gear.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
gear.animate().scaleX(1.5f).scaleY(1.5f).setDuration(500);
animateDiagonalPan();
icon1 = findViewById(R.id.icon1);
icon1.animate().translationXBy(120).translationYBy(120).setDuration(500);
if(chkClick==0)
{
pulseView.animate().alpha(0).setDuration(500);
gear.animate().scaleX(1.5f).scaleY(1.5f).setDuration(500);
pulseView.finishPulse();
chkClick = 1;
}else{
pulseView.animate().alpha(1f).setDuration(500);
gear.animate().scaleX(1f).scaleY(1f).setDuration(500);
pulseView.startPulse();
chkClick = 0;
}
}
});
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:background="#f39c12"
tools:context="com.rootonelabs.vicky.pulse.MainActivity">
<LinearLayout
android:orientation="horizontal"
android:layout_alignParentBottom="true"
android:weightSum="2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btnStart"
android:layout_weight="1"
android:text="START"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/btnStop"
android:layout_weight="1"
android:text="STOP"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
<ImageView
android:id="#+id/gear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/men3"/>
<ImageView
android:id="#+id/icon1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_action_video"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_action_archive"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_attachment_black_24dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_action_video"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_action_archive"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_attachment_black_24dp"/>
<com.gigamole.library.PulseView
android:id="#+id/pv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
app:pv_alpha="70"
app:pv_color="#FFF"
app:pv_icon="#drawable/men2"
app:pv_icon_width="100dp"
app:pv_icon_height="100dp"
app:pv_interpolator="#android:anim/linear_interpolator"
app:pv_measure="height"
app:pv_spawn_period="1000" />
</RelativeLayout>

EditText's not changing on ImageButton press?

I am very new to coding so there could be all sorts of issues with this but after doing a fair bit of searching, I can't find whats wrong with it, I don't get any errors or crashes, the buttons just do nothing?
The aim is to have the orange arrows increase and decrease the number in the middle by 1.
App Screenshot:
I don't know what code to show you so here is most of it:
T3_TrampetFragment.java
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class T3_TrampetFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.t3_trampetlayout, container, false);
}
}
t3_trampetlayout.xml
<RelativeLayout 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="wrap_content"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".T3_TrampetFragment">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow
android:id="#+id/tblrow_title"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/txt_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Tariff Calculator"
android:textAlignment="center"
android:textColor="#color/colorPrimaryDark"
android:textSize="36sp"
android:textStyle="bold" />
</TableRow>
<TableRow
android:id="#+id/tblrow_rotations"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="#+id/txt_rotations"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Rotations"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="24sp" />
<ImageButton
android:id="#+id/btn_r_minus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true"
android:rotation="180" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/Rnum"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"
android:focusable="false"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/sRnum"
android:textAlignment="center"
android:textColor="?attr/colorControlNormal"
android:textSize="24sp"
android:textStyle="bold" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<ImageButton
android:id="#+id/btn_r_plus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true" />
<Space
android:layout_width="20dp"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tblrow_pike"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="#+id/txt_pike"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Pike Bonus"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="24sp" />
<ImageButton
android:id="#+id/btn_p_minus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true"
android:rotation="180" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/Pnum"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"
android:focusable="false"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/sPnum"
android:textAlignment="center"
android:textColor="?attr/colorControlNormal"
android:textSize="24sp"
android:textStyle="bold" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<ImageButton
android:id="#+id/btn_p_plus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true" />
<Space
android:layout_width="20dp"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tblrow_straight"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="#+id/txt_straight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Straight Bonus"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="24sp" />
<ImageButton
android:id="#+id/btn_s_minus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true"
android:rotation="180" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/Snum"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"
android:focusable="false"
android:inputType="number"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/sSnum"
android:textAlignment="center"
android:textColor="?attr/colorControlNormal"
android:textSize="24sp"
android:textStyle="bold" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<ImageButton
android:id="#+id/btn_s_plus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true" />
<Space
android:layout_width="20dp"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tblrow_twist"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="10dp"
android:paddingTop="10dp">
<TextView
android:id="#+id/txt_twist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Twists"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="24sp" />
<ImageButton
android:id="#+id/btn_t_minus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true"
android:rotation="180" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/Tnum"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"
android:focusable="false"
android:inputType="numberDecimal"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/sTnum"
android:textAlignment="center"
android:textColor="?attr/colorControlNormal"
android:textSize="24sp"
android:textStyle="bold" />
<Space
android:layout_width="10dp"
android:layout_height="wrap_content" />
<ImageButton
android:id="#+id/btn_t_plus"
android:layout_height="40dp"
android:layout_marginTop="5dp"
android:backgroundTint="?android:attr/colorBackground"
android:clickable="true"
android:foreground="#android:drawable/ic_media_play"
android:foregroundTint="#color/colorSecondary"
android:hapticFeedbackEnabled="true" />
<Space
android:layout_width="20dp"
android:layout_height="wrap_content" />
</TableRow>
<TableRow
android:id="#+id/tblrow_result"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="20dp"
android:paddingTop="20dp">
<TextView
android:id="#+id/txt_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="Difficulty"
android:textAlignment="center"
android:textColor="#color/colorPrimary"
android:textSize="24sp"
android:textStyle="bold" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/_space"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:rotation="180"
android:visibility="invisible"
app:backgroundTint="#color/colorSecondary"
app:fabSize="mini"
app:srcCompat="#android:drawable/ic_media_play" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/Resultnum"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:background="?android:attr/colorBackground"
android:focusable="false"
android:inputType="numberDecimal"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="#string/sResultnum"
android:textAlignment="center"
android:textColor="?attr/colorControlNormal"
android:textSize="24sp"
android:textStyle="bold" />
<Space
android:layout_width="0dp"
android:layout_height="wrap_content" />
<android.support.design.widget.FloatingActionButton
android:id="#+id/_space2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:visibility="invisible"
app:backgroundTint="#color/colorSecondary"
app:fabSize="mini"
app:srcCompat="#android:drawable/ic_media_play" />
<Space
android:layout_width="20dp"
android:layout_height="wrap_content" />
</TableRow>
</TableLayout>
</RelativeLayout>
T3_TrampetActivity.java
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.EditText;
public class T3_TrampetActivity extends Activity implements View.OnClickListener {
ImageButton BtnRMinus, BtnRPlus, BtnPMinus, BtnPPlus, BtnSMinus, BtnSPlus, BtnTMinus, BtnTPlus;
EditText R_num, P_num, S_num, T_num, Result_num;
int R_counter = (1);
int P_counter, S_counter = (0);
double T_counter = (0.0);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.t3_trampetlayout);
R_num = (EditText) findViewById(R.id.Rnum);
P_num = (EditText) findViewById(R.id.Pnum);
S_num = (EditText) findViewById(R.id.Snum);
T_num = (EditText) findViewById(R.id.Tnum);
Result_num = (EditText) findViewById(R.id.Resultnum);
BtnRMinus = (ImageButton) findViewById(R.id.btn_r_minus);
BtnRPlus = (ImageButton) findViewById(R.id.btn_r_plus);
BtnPMinus = (ImageButton) findViewById(R.id.btn_p_minus);
BtnPPlus = (ImageButton) findViewById(R.id.btn_p_plus);
BtnSMinus = (ImageButton) findViewById(R.id.btn_s_minus);
BtnSPlus = (ImageButton) findViewById(R.id.btn_s_plus);
BtnTMinus = (ImageButton) findViewById(R.id.btn_t_minus);
BtnTPlus = (ImageButton) findViewById(R.id.btn_t_plus);
BtnRMinus.setOnClickListener(this);
BtnRPlus.setOnClickListener(this);
BtnPMinus.setOnClickListener(this);
BtnPPlus.setOnClickListener(this);
BtnSMinus.setOnClickListener(this);
BtnSPlus.setOnClickListener(this);
BtnTMinus.setOnClickListener(this);
BtnTPlus.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_r_minus:
if (R_counter > 1) {
--R_counter;
R_num.setText(String.valueOf(R_counter));
}
break;
case R.id.btn_r_plus:
if (R_counter < 3) {
++R_counter;
R_num.setText(String.valueOf(R_counter));
}
break;
case R.id.btn_p_minus:
if (P_counter > 0) {
--P_counter;
P_num.setText(String.valueOf(P_counter));
}
break;
case R.id.btn_p_plus:
if (P_counter < 3) {
++P_counter;
P_num.setText(String.valueOf(P_counter));
}
break;
case R.id.btn_s_minus:
if (S_counter > 0) {
--S_counter;
S_num.setText(String.valueOf(S_counter));
}
break;
case R.id.btn_s_plus:
if (S_counter < 3) {
++S_counter;
S_num.setText(String.valueOf(S_counter));
}
break;
case R.id.btn_t_minus:
if (T_counter > 0) {
T_counter = (T_counter - 0.5);
T_num.setText(String.valueOf(T_counter));
}
break;
case R.id.btn_t_plus:
if (T_counter < 5.5) {
T_counter = (T_counter + 0.5);
T_num.setText(String.valueOf(T_counter));
}
break;
default:
break;
}
}
}
strings.xml
<resources>
<string name="app_name">TG Mobile</string>
<string name="in_app_name">TeamGym Mobile</string>
<string name="sRnum">1</string>
<string name="sPnum">0</string>
<string name="sSnum">0</string>
<string name="sTnum">0.0</string>
<string name="sResultnum">0.00</string>
</resources>
Create T3_TrampetActivity like this And Call Your Fragment from Activity:
public class T3_TrampetActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Fragment fragment = new T3_TrampetFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragment_frame, fragment, fragment.getClass().getSimpleName()).addToBackStack(null).commit();
}
}
Create activity_main.xml as like this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/fragment_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Update T3_TrampetFragment.java
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class T3_TrampetFragment extends Fragment implements View.OnClickListener {
ImageButton BtnRMinus, BtnRPlus, BtnPMinus, BtnPPlus, BtnSMinus, BtnSPlus, BtnTMinus, BtnTPlus;
EditText R_num, P_num, S_num, T_num, Result_num;
int R_counter = (1);
int P_counter, S_counter = (0);
double T_counter = (0.0);
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.t3_trampetlayout, container, false);
R_num = (EditText) view.findViewById(R.id.Rnum);
P_num = (EditText) view.findViewById(R.id.Pnum);
S_num = (EditText) view.findViewById(R.id.Snum);
T_num = (EditText) view.findViewById(R.id.Tnum);
Result_num = (EditText) view.findViewById(R.id.Resultnum);
BtnRMinus = (ImageButton) view.findViewById(R.id.btn_r_minus);
BtnRPlus = (ImageButton)view.findViewById(R.id.btn_r_plus);
BtnPMinus = (ImageButton) view.findViewById(R.id.btn_p_minus);
BtnPPlus = (ImageButton) view.findViewById(R.id.btn_p_plus);
BtnSMinus = (ImageButton) view.findViewById(R.id.btn_s_minus);
BtnSPlus = (ImageButton) view.findViewById(R.id.btn_s_plus);
BtnTMinus = (ImageButton) view.findViewById(R.id.btn_t_minus);
BtnTPlus = (ImageButton) view.findViewById(R.id.btn_t_plus);
BtnRMinus.setOnClickListener(this);
BtnRPlus.setOnClickListener(this);
BtnPMinus.setOnClickListener(this);
BtnPPlus.setOnClickListener(this);
BtnSMinus.setOnClickListener(this);
BtnSPlus.setOnClickListener(this);
BtnTMinus.setOnClickListener(this);
BtnTPlus.setOnClickListener(this);
return view;
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_r_minus:
if (R_counter > 1) {
--R_counter;
R_num.setText(String.valueOf(R_counter));
}
break;
case R.id.btn_r_plus:
if (R_counter < 3) {
++R_counter;
R_num.setText(String.valueOf(R_counter));
}
break;
case R.id.btn_p_minus:
if (P_counter > 0) {
--P_counter;
P_num.setText(String.valueOf(P_counter));
}
break;
case R.id.btn_p_plus:
if (P_counter < 3) {
++P_counter;
P_num.setText(String.valueOf(P_counter));
}
break;
case R.id.btn_s_minus:
if (S_counter > 0) {
--S_counter;
S_num.setText(String.valueOf(S_counter));
}
break;
case R.id.btn_s_plus:
if (S_counter < 3) {
++S_counter;
S_num.setText(String.valueOf(S_counter));
}
break;
case R.id.btn_t_minus:
if (T_counter > 0) {
T_counter = (T_counter - 0.5);
T_num.setText(String.valueOf(T_counter));
}
break;
case R.id.btn_t_plus:
if (T_counter < 5.5) {
T_counter = (T_counter + 0.5);
T_num.setText(String.valueOf(T_counter));
}
break;
default:
break;
}
}
}
t3_trampetlayout.xml Use same layou for Fragment.

App force closes when I click on a page

I designed a profile page of an android app. But, it force closes when I click to this page. How can I prevent crash?
Reference of my profile page
res/layout/fragment_profile_vp.xml
<FrameLayout 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="com.example.ray.myoufd.Profile_vp">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/header_cover_image"
android:layout_width="match_parent"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="#drawable/profilebg" />
<ImageButton
android:id="#+id/user_profile_photo"
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_below="#+id/header_cover_image"
android:layout_centerHorizontal="true"
android:layout_marginTop="-60dp"
android:elevation="5dp"
android:scaleType="centerCrop"
android:src="#drawable/defaultpropic" />
<RelativeLayout
android:id="#+id/profile_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/header_cover_image"
android:background="#color/grey"
android:elevation="4dp"
android:paddingBottom="24dp">
<TextView
android:id="#+id/user_profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="76dp"
android:text="Name"
android:textColor="#fff"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/user_profile_short_bio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/user_profile_name"
android:layout_centerHorizontal="true"
android:layout_marginTop="12dp"
android:text="profile short bio"
android:textColor="#fff"
android:textSize="14sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_layout"
android:layout_marginTop="0dp"
android:orientation="horizontal"
android:id="#+id/linearLayout1"
android:background="#color/white">
<TextView
android:layout_height="wrap_content"
android:text="Name:"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="#color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="#color/black"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_layout"
android:layout_marginTop="43dp"
android:orientation="horizontal"
android:id="#+id/linearLayout2"
android:background="#color/white">
<TextView
android:layout_height="wrap_content"
android:text="Gender:"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="#color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="#color/black"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_layout"
android:layout_marginTop="86dp"
android:orientation="horizontal"
android:id="#+id/linearLayout3"
android:background="#color/white" >
<TextView
android:layout_height="wrap_content"
android:text="Email:"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="#color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="#color/black"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_layout"
android:layout_marginTop="129dp"
android:orientation="horizontal"
android:id="#+id/linearLayout4"
android:background="#color/white">
<TextView
android:layout_height="wrap_content"
android:text="Date o birth:"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="#color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="#color/black"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/profile_layout"
android:layout_marginTop="172dp"
android:orientation="vertical"
android:id="#+id/linearLayout5"
android:background="#color/white">
<TextView
android:layout_height="wrap_content"
android:text="Message to friend"
android:layout_width="wrap_content"
android:textSize="18sp"
android:layout_margin="5dp"
android:textColor="#color/green"/>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textColor="#color/black"/>
</LinearLayout>
<Button
android:text="Logout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button"
android:layout_marginStart="115dp"
android:layout_marginLeft="115dp"
android:background="#color/green"
android:layout_marginTop="605dp" />
<Button
android:text="Save"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button2"
android:layout_marginTop="605dp"
android:layout_marginLeft="210dp"
android:layout_marginStart="210dp"
android:background="#color/green"
/>
</RelativeLayout>
</ScrollView>
</FrameLayout>
java/com.example.ray.myoufd/Profile_vp.java
package com.example.ray.myoufd;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Profile_vp extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_profile_vp, container, false);
}
}
java/com.example.ray.myoufd/MainPage.java
package com.example.ray.myoufd;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import com.gigamole.navigationtabbar.ntb.NavigationTabBar;
import java.util.ArrayList;
import java.util.List;
public class MainPage extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_page);
initUI();
}
private void initUI() {
final ViewPager viewPager = (ViewPager) findViewById(R.id.vp_horizontal_ntb);
final String[] colors = getResources().getStringArray(R.array.default_preview);
final NavigationTabBar navigationTabBar = (NavigationTabBar) findViewById(R.id.ntb_horizontal);
final ArrayList<NavigationTabBar.Model> models = new ArrayList<>();
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.home),
Color.parseColor(colors[0]))
.title("Home")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.search),
Color.parseColor(colors[1]))
.title("Search")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.friend),
Color.parseColor(colors[2])).
badgeTitle("123")
.title("Friend")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.personal),
Color.parseColor(colors[3]))
.title("Profile")
.build()
);
models.add(
new NavigationTabBar.Model.Builder(
getResources().getDrawable(R.drawable.chat),
Color.parseColor(colors[4]))
.title("Discuss")
.build()
);
navigationTabBar.setModels(models);
Search_vp search_Vp = new Search_vp();
Home_vp home_vp = new Home_vp();
Friend_vp friend_vp =new Friend_vp();
Discuss_vp discuss_vp = new Discuss_vp();
Profile_vp profile_vp = new Profile_vp();
List<Fragment> fragmentList = new ArrayList<>();
fragmentList.add(home_vp);
fragmentList.add(search_Vp);
fragmentList.add(friend_vp);
fragmentList.add(profile_vp);
fragmentList.add(discuss_vp);
FragmentPageAdapter fragmentPageAdapter =new FragmentPageAdapter(getSupportFragmentManager(),fragmentList);
viewPager.setAdapter(fragmentPageAdapter);
navigationTabBar.setViewPager(viewPager, 0);
navigationTabBar.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(final int position, final float positionOffset, final int positionOffsetPixels) {
}
#Override
public void onPageSelected(final int position) {
navigationTabBar.getModels().get(position).hideBadge();
}
#Override
public void onPageScrollStateChanged(final int state) {
}
});
navigationTabBar.postDelayed(new Runnable() {
#Override
public void run() {
for (int i = 0; i < navigationTabBar.getModels().size(); i++) {
final NavigationTabBar.Model model = navigationTabBar.getModels().get(i);
navigationTabBar.postDelayed(new Runnable() {
#Override
public void run() {
model.showBadge();
}
}, i * 100);
}
}
}, 500);
}
}

Working with the Slide in menu

So I have some code for a slide in menu and when I click a button I wont it to bring up the new layout but still have the slide in menu. Here is my Main Activity code:
public class MainActivity extends Activity implements OnClickListener {
ImageButton menu_button;
Button p1, p2, p3, p4;
LinearLayout content, menu;
LinearLayout.LayoutParams contentParams;
TranslateAnimation slide;
int marginX, animateFromX, animateToX = 0;
boolean menuOpen = false;
#SuppressWarnings("deprecation")
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_layout);
menu = (LinearLayout)findViewById(R.id.menu);
content = (LinearLayout)findViewById(R.id.content);
contentParams = (LinearLayout.LayoutParams)content.getLayoutParams();
contentParams.width = getWindowManager().getDefaultDisplay().getWidth();
contentParams.leftMargin = -(menu.getLayoutParams().width);
content.setLayoutParams(contentParams);
menu_button = (ImageButton)findViewById(R.id.menu_button);
menu_button.setOnClickListener(this);
p1 = (Button)findViewById(R.id.p1);
p1.setOnClickListener(this);
p2 = (Button)findViewById(R.id.p2);
p2.setOnClickListener(this);
p3 = (Button)findViewById(R.id.p3);
p3.setOnClickListener(this);
p4 = (Button)findViewById(R.id.p4);
p4.setOnClickListener(this);
}
public boolean onKeyDown(int keyCode, KeyEvent keyEvent) {
if(keyCode == KeyEvent.KEYCODE_BACK) {
if(menuOpen) {
slideMenuIn(0, -(menu.getLayoutParams().width), -(menu.getLayoutParams().width));
menuOpen = false;
return true;
}
}
return super.onKeyDown(keyCode, keyEvent);
}
public void onClick(View v) {
switch(v.getId()) {
case R.id.p1:
// What do I put here to make this happen?
break;
case R.id.p2:
break;
case R.id.p3:
break;
case R.id.p4:
break;
}
if(contentParams.leftMargin == -(menu.getLayoutParams().width)) {
animateFromX = 0;
animateToX = (menu.getLayoutParams().width);
marginX = 0;
menuOpen = true;
} else {
animateFromX = 0;
animateToX = -(menu.getLayoutParams().width);
marginX = -(menu.getLayoutParams().width);
menuOpen = false;
}
slideMenuIn(animateFromX, animateToX, marginX);
}
public void slideMenuIn(int animateFromX, int animateToX, final int marginX){
slide = new TranslateAnimation(animateFromX, animateToX, 0, 0);
slide.setDuration(300);
slide.setFillEnabled(true);
slide.setAnimationListener(new AnimationListener() {
public void onAnimationEnd(Animation animation) {
contentParams.setMargins(marginX, 0, 0, 0);
content.setLayoutParams(contentParams);
}
public void onAnimationRepeat(Animation animation) { }
public void onAnimationStart(Animation animation) { }
});
content.startAnimation(slide);
}
}
This is my main XML with the Slide in menu:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/menu"
android:layout_height="fill_parent"
android:layout_width="150dip"
android:background="#f2f2f2"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="2dip"
android:background="#000"
android:layout_marginTop="50dip" />
<Button
android:id="#+id/p1"
android:text="1"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:textSize="18sp"
android:background="#drawable/states" />
<TextView
android:layout_width="match_parent"
android:layout_height="2dip"
android:background="#000" />
<Button
android:id="#+id/p2"
android:text="2"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:textSize="18sp"
android:background="#drawable/states" />
<TextView
android:layout_width="match_parent"
android:layout_height="2dip"
android:background="#000" />
<Button
android:id="#+id/p3"
android:text="3"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:textSize="18sp"
android:background="#drawable/states" />
<TextView
android:layout_width="match_parent"
android:layout_height="2dip"
android:background="#000" />
<Button
android:id="#+id/p4"
android:text="3"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:textSize="18sp"
android:background="#drawable/states" />
<TextView
android:layout_width="match_parent"
android:layout_height="2dip"
android:background="#000" />
</LinearLayout>
<LinearLayout
android:id="#+id/content"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dip"
android:orientation="horizontal"
android:background="#f2f2f2" >
<ImageButton
android:id="#+id/menu_button"
android:layout_width="50dip"
android:layout_height="50dip"
android:background="#drawable/states"
android:src="#drawable/options"
android:contentDescription="#string/app_name" />
<TextView
android:text="FirstApp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#333"
android:textSize="24sp"
android:paddingTop="14dip"
android:gravity="center" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="2dip"
android:background="#000" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="#fff" >
<TextView
android:id="#+id/paragraph"
android:textSize="20sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dip" />
</ScrollView>
</LinearLayout>
</LinearLayout>
And Finally this is the Xml that I whant to appear when the first button in the Slide In menu is clicked:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFFFFF" >
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp"
android:ems="10"
android:hint="Box 1" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_alignLeft="#+id/editText1"
android:layout_below="#+id/editText1"
android:ems="10"
android:hint="Box 2" />
</RelativeLayout>
Please Help.

Categories

Resources