There is an ImageButton in activity. By clicking on them, it is necessary that these pictures appear in a specially designated field. Pictures in it appear in the order in which they clicked on their originals. By clicking on the picture in the field, it disappears. What structure and how best to use to create such a field? I'm just learning and using eclipse to create an application.
2 answers
ImageView to use. For each image. Add a new ImageView to LinearLayout, and set it imageView.setImageDrawable(imageButton.getDrawable());
when you click on imageButton. When you click on imageView, simply remove it from the parent.
|
- Need a container, such as LinearLayout. You can add it to the xml markup file in advance:
<LinearLayout android:id="@+id/conteiner" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"/>
Further in the code, you can add images to the container, for example on onClick
//Π½Π°Ρ ΠΎΠ΄ΠΈΠΌ ΠΊΠΎΠ½ΡΠ΅ΠΉΠ½Π΅Ρ LinearLayout layout = (LinearLayout) findViewById(R.id.conteiner); //ΡΠΎΠ·Π΄Π°Π΅ΠΌ Π²ΠΈΠ΄ΠΆΠ΅Ρ ImageView imageView = new ImageView(MainActivity.this); imageView.setImageResource(R.mipmap.ic_launcher); //Π΄ΠΎΠ±Π°Π²Π»ΡΠ΅ΠΌ Π²ΠΈΠ΄ΠΆΠ΅Ρ Π² ΠΊΠΎΠ½ΡΠ΅ΠΉΠ½Π΅Ρ layout.addView(imageView);
- Thanks, very helpful. If it's not difficult for you, can you say more, how to make the images added to the container from top to bottom? Used both horizontal and vertical LinearLayout, did not help. - Alena Fedorova
|