Android 以编程方式在布局顶部绘制图像
我有一个问题,在网上我找不到任何解决办法 我有一个如下的xml布局(我简化了它,并且有理由这样格式化):Android 以编程方式在布局顶部绘制图像,android,layout,canvas,overlay,draw,Android,Layout,Canvas,Overlay,Draw,我有一个问题,在网上我找不到任何解决办法 我有一个如下的xml布局(我简化了它,并且有理由这样格式化): 现在,如果在某个事件之后,我想在4个ImageView代码中的1个上绘制一个图像,我必须做什么 (我不想使用background+src技巧来完成这项工作) 先谢谢你 任何帮助都将不胜感激 弗朗西斯科 编辑: 总的来说,我的问题是,我希望仍然使用xml声明布局,并在任何我希望的代码位置放置一个图像 再次感谢您 <LinearLayout android:lay
现在,如果在某个事件之后,我想在4个ImageView代码中的1个上绘制一个图像,我必须做什么
(我不想使用background+src技巧来完成这项工作)
先谢谢你
任何帮助都将不胜感激
弗朗西斯科
编辑:
总的来说,我的问题是,我希望仍然使用xml声明布局,并在任何我希望的代码位置放置一个图像
再次感谢您
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="20"
android:orientation="horizontal"
android:background="#FFFFFF"
>
</LinearLayout>
Assign An id to LinearLayout
View v = new ImageView(getBaseContext());
ImageView image;
image = new ImageView(v.getContext());
image.setImageDrawable(v.getResources().getDrawable(R.drawable.gameover));
LinearLayout linlayout = findViewById(R.layout.current_layout);
linlayout.addview(v);
为LinearLayout分配一个id
视图v=新的图像视图(getBaseContext());
图像视图图像;
image=newimageview(v.getContext());
setImageDrawable(v.getResources().getDrawable(R.drawable.gameover));
LinearLayout linlayout=findViewById(R.layout.current_layout);
linlayout.addview(v);
你想在imageview上绘制任何形状吗?您好,Jogendra是png图像,所以问题是如果我选择另一个imageview,那么我必须创建另一个imageview,将其放入相对视图(我没有),并使用alignTop属性,但我不知道将覆盖imageview放置在哪里,因为它可以覆盖不同的imageview。。我认为解决方案会有所不同。你能发布你的整个布局(xml)吗?我已经编辑了添加整个布局的帖子。视图=(视图)findViewById(R.layout.current\u layout)//在setContentView()
LinearLayout picLL=newlinearLayout(CurrentActivity.this)中设置的布局;微小布局(0,0,100,0);picLL.setLayoutParams(新的LayoutParams(1000,60));设置方向(线性布局。水平);((视图组)视图)。添加视图(picLL);您好Jogendra和TY快速回复,我的观点是,在这种情况下,由于叠加图像每次都应基于事件应用于不同的图像,因此我需要每次添加视图,然后删除视图,并添加到另一个线性布局等。同样,对于线性布局,我恐怕不可能有叠加图像。。我认为解决方案更像是在某个坐标系绘制画布,然后在另一个坐标系重新显示,但我不知道如何在不丢失当前布局的情况下实现这一点。。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="20"
android:orientation="horizontal"
android:background="#FFFFFF"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="15"
android:orientation="horizontal"
android:background="#FFFFFF"
>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<ImageButton
android:id="@+id/imagebutton1"
android:onClick="imagebutton1_code"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="match_parent"
android:background="@null"
android:scaleType="fitCenter"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<ImageButton
android:id="@+id/imagebutton2"
android:onClick="imagebutton2_code"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="match_parent"
android:background="@null"
android:scaleType="fitCenter"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="5"
android:orientation="horizontal"
android:background="#FFFFFF"
>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="15"
android:orientation="horizontal"
android:background="#FFFFFF"
>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<ImageButton
android:id="@+id/imagebutton3"
android:onClick="imagebutton3_code"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="match_parent"
android:background="@null"
android:scaleType="fitCenter"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<ImageButton
android:id="@+id/imagebutton4"
android:onClick="imagebutton4_code"
android:layout_width="0dp"
android:layout_weight="3"
android:layout_height="match_parent"
android:background="@null"
android:scaleType="fitCenter"
/>
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="18"
android:orientation="horizontal"
android:background="#FFFFFF"
>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="20"
android:orientation="horizontal"
android:background="#FFFFFF"
>
</LinearLayout>
Assign An id to LinearLayout
View v = new ImageView(getBaseContext());
ImageView image;
image = new ImageView(v.getContext());
image.setImageDrawable(v.getResources().getDrawable(R.drawable.gameover));
LinearLayout linlayout = findViewById(R.layout.current_layout);
linlayout.addview(v);