- Good afternoon, I created a small application and I went to the phone to experience how well it was on my phone. I gave my friends to see if it worked well on their phone. I ended up finding out that in some it is slow and in others it is fast. Getting really slow on good phones. I need help.
Code (Main_activity):
public class MainActivity extends AppCompatActivity {
Button b_flip1;
Button b_flip2;
ImageView iv_coin1;
ImageView iv_coin2;
Random r;
Random r1;
int coinSide;
int coinSide1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b_flip1 = (Button) findViewById(R.id.b_flip1);
b_flip2 = (Button) findViewById(R.id.b_flip2);
iv_coin1 = (ImageView) findViewById(R.id.iv_coin1);
iv_coin2 = (ImageView) findViewById(R.id.iv_coin2);
r = new Random();
r1 = new Random();
//codigo button 1 ............................................................................
b_flip1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
coinSide = r.nextInt(7);
if (coinSide == 0){
iv_coin1.setImageResource(R.drawable.ummpt);
} else if (coinSide == 1){
iv_coin1.setImageResource(R.drawable.doissspt);
} else if (coinSide == 2){
iv_coin1.setImageResource(R.drawable.tressspt);
}else if (coinSide == 3){
iv_coin1.setImageResource(R.drawable.quatrooopt);
}else if (coinSide == 4){
iv_coin1.setImageResource(R.drawable.cincoopt);
}else if (coinSide == 5){
iv_coin1.setImageResource(R.drawable.seissspt);
}
RotateAnimation rotate = new RotateAnimation(0,360,
RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(1000);
iv_coin1.startAnimation(rotate);
}
});
//codigo button 2 .............................................................................
b_flip2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
coinSide1 = r1.nextInt(7);
if (coinSide1 == 0){
iv_coin2.setImageResource(R.drawable.seteept);
} else if (coinSide1 == 1){
iv_coin2.setImageResource(R.drawable.oitoopt);
} else if (coinSide1 == 2){
iv_coin2.setImageResource(R.drawable.noveept);
}else if (coinSide1 == 3){
iv_coin2.setImageResource(R.drawable.dezzpt);
}else if (coinSide1 == 4){
iv_coin2.setImageResource(R.drawable.onzeept);
}else if (coinSide1 == 5){
iv_coin2.setImageResource(R.drawable.dozeeept);
}
RotateAnimation rotate = new RotateAnimation(0,360,
RotateAnimation.RELATIVE_TO_SELF, 0.5f, RotateAnimation.RELATIVE_TO_SELF, 0.5f);
rotate.setDuration(1000);
iv_coin2.startAnimation(rotate);
}
});
}
}
............................................... ..................
Layout
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ummpt"
android:elevation="21dp"
android:id="@+id/iv_coin1"
android:layout_weight="1" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:elevation="21dp"
android:id="@+id/iv_coin2"
android:layout_weight="1"
app:srcCompat="@drawable/seteept" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:layout_width="wrap_content"
android:id="@+id/b_flip1"
android:layout_weight="1"
android:layout_height="wrap_content"
android:background="@drawable/buttondois" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/b_flip2"
android:layout_weight="1"
android:background="@drawable/buttondois" />
</LinearLayout>
</LinearLayout>