0
- Good afternoon, I created a small application and went to the phone to try how well it ran on my phone I gave it to my friends to see if it worked on their phone. I ended up discovering that in some it gets slow and in others fast. Getting really slow on good capacity 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>
You can clarify what slows down?
– Carlos Bridi
Application has two wheels that rotate when you click a button.Each wheel has a button. They rotate change the image of the wheel.. And this part is slow.. ON some phones, when you click the button the wheels rotate very slowly , even taking 20 seconds..
– sergiopm
You can put them spinning inside a trhead, one for each, then vacate the main thread and leave them in the daughters..
– Carlos Bridi