gpt4 book ai didi

Android layoutdisplay,layout over layout。

转载 作者:行者123 更新时间:2023-11-30 04:16:28 25 4
gpt4 key购买 nike

enter image description here

如图所示。我想在布局上方显示星图。我是这种编码的新手。

我的查询是1)是否可以在我的布局端显示星标(图像)?

2) 如果每次点击我的 Activity 时我都想显示星标并显示第二张图片,这可能吗?意味着在同一屏幕上我必须用他们尊重的位置来保存星星。

enter image description here感谢高级?

最佳答案

像这样:

 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;
}
}

主.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>

关于Android layoutdisplay,layout over layout。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9906080/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com