我正在尝试将两个图像放在一起。我可以让它与 xml 文件一起正常工作,但我想动态地执行此操作。 ctdeasyone 是一个透明图像。
所以这工作正常..
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/bck1"
android:src="@drawable/fish2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:layout_gravity="center">
</ImageView>
<ImageView
android:id="@+id/bck2"
android:src="@drawable/ctdeasyone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:layout_gravity="center">
</ImageView>
</RelativeLayout>
当我这样做的时候。仅显示第二张图像(它是透明的。)任何专家都可以对此提出建议吗?这里是新手...这是我的第一个问题。 TIA。
public class TwoPicksOnEachOther extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Grabbing the Application context
final Context context = getApplication();
RelativeLayout relativeLayout = new RelativeLayout(this);
final ImageView iv = new ImageView(this);
iv.setImageResource(R.drawable.fish2);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
relativeLayout.addView(iv,lp);
// Creating transparent image
final ImageView iv2 = new ImageView(this);
iv.setImageResource(R.drawable.ctdeasytwo);
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
relativeLayout.addView(iv2,lp2);
setContentView(relativeLayout);
}
}
我不得不将它放入模拟器中并玩了一段时间,直到我看到它:
iv.setImageResource(R.drawable.fish2);
(...)
iv.setImageResource(R.drawable.ctdeasytwo);
您永远不会为 iv2 设置图像资源!
我改变了它,现在我看到了预期的两张图像。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)