Search code examples
androidimageviewtablelayout

Android: how to show and move ImageView in TableLayout


I have a grid of TextViews shown inside a TableLayout. When the user taps a TextView I need to change the cell's background by adding an ImageView that will go to another cell when other cells will be clicked.
Which is the best way to do this in Android?


Solution

  • TextView can have an image (drawable) as a background. So it is easy to do it with textView.setBackgroundDrawable(R.drawable.myimage);

    You can move the image into any cell-textView with this method and set the previous to another image or nothing with textView.setBackgroundDrawable(null);

    You cannot animate this movement in the table, because each row is one view an may limit the animation of its children views to its constrains.