
如图所示。我想要显示上面布局的星形图像。我对这种类型的编码还不熟悉。
我的问题是1)是否可以在我的布局侧显示星形(图像)?
2)如果每次点击我的事件时,我想要像星形一样显示,并且像第二张图像一样显示,可以吗?意味着在同一个屏幕上,我必须保存明星和他们尊重的位置。

在高级中感谢?
发布于 2012-03-28 19:26:56
如下所示:
public class MyActivity extends Activity implements View.OnTouchListener {
private RelativeLayout _mainLayout;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_mainLayout = (RelativeLayout)findViewById(R.id.canvas);
_mainLayout.setOnTouchListener(this);
}
@Override
public boolean onTouch(View view, MotionEvent event) {
final int X = (int) event.getRawX();
final int Y = (int) event.getRawY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
ImageView image = new ImageView(this);
image.setImageBitmap(bitmap);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(bitmap.getWidth(), bitmap.getHeight());
layoutParams.leftMargin = X - bitmap.getWidth()/2;
layoutParams.topMargin = Y - bitmap.getHeight()/2;
layoutParams.bottomMargin = -250;
layoutParams.rightMargin = -250;
image.setLayoutParams(layoutParams);
_mainLayout.addView(image);
break;
}
return false;
}
}main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/canvas"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/bg0large"
>
</RelativeLayout>
发布于 2012-03-28 19:06:23
要使布局重于布局,您应该使用RelativeLayout。
发布于 2012-03-28 19:19:55
如果要在另一个布局上显示一个布局,则应使用FrameLayout http://developer.android.com/resources/articles/layout-tricks-merge.html
https://stackoverflow.com/questions/9906080
复制相似问题