【发布时间】:2015-03-12 11:40:54
【问题描述】:
我在设置一些代码时遇到问题,这些代码允许我通过连续单击两个 imageView(一个带有源图像,然后是目标 imageView)将一个 imageView 的可绘制对象移动到另一个 imageView。
目标是模拟棋盘。
我的起始显示如下:
然后我点击最左边的pawn然后直接点击它前面的方块,结果如下。您会看到目标 imageView(第一列第 3 行)正在失去其水平边界定义并在整个 tableRow 中扩展:
现在,我还重置标签以及每个方块中的可绘制对象,但我认为问题源于我获取和设置可绘制对象的方式。
我的代码如下:
int selectedId = getResources().getIdentifier(selectedSquare, "id", getPackageName());
ImageView sourceSquare = (ImageView) findViewById(selectedId);
Drawable sourceDrawable = sourceSquare.getDrawable();
ImageView targetSquare = (ImageView) findViewById(R.id.s20);
targetSquare.setImageDrawable(sourceDrawable);
我的猜测是,我正在创建的 sourceDrawable 变量以某种方式获取了太多或太少的信息,当我将该可绘制对象移动到新的 imageView targetSquare 时,这会破坏我的格式。
【问题讨论】:
标签: java android android-layout imageview android-drawable