Canvas 顶部的按钮
Button on top of a Canvas
我正在尝试将一个按钮放在一个视图之上,我将其与 Canvas 一起使用,但无法解决。
有什么想法吗?我到处都看了(这似乎是一个常见的问题)但没有找到任何解决方案。
谢谢,
public class MyActivity extends Activity {
private RandomShapeView mDrawingArea;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
mDrawingArea = (RandomShapeView) findViewById(R.id.drawing_area);
mDrawingArea.setBackgroundColor(Color.GREEN);
}
}
查看Class
public class RandomShapeView extends View {
Paint paint;
public RandomShapeView(Context context) {
super(context);
paint = new Paint();
paint.setColor(Color.BLACK);
}
@Override
protected void onDraw(Canvas canvas) {
}
}
布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">
<Button
android:id="@+id/button"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
class="com.examples.danilofernandes.canvasonrelativelayout.RandomShapeView"
android:id="@+id/drawing_area"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
Z 顺序隐含在元素在 XML 中出现的顺序中。换个地方,应该没问题。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">
<com.examples.danilofernandes.canvasonrelativelayout.RandomShapeView
android:id="@+id/drawing_area"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<Button
android:id="@+id/button"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
我正在尝试将一个按钮放在一个视图之上,我将其与 Canvas 一起使用,但无法解决。
有什么想法吗?我到处都看了(这似乎是一个常见的问题)但没有找到任何解决方案。
谢谢,
public class MyActivity extends Activity {
private RandomShapeView mDrawingArea;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
mDrawingArea = (RandomShapeView) findViewById(R.id.drawing_area);
mDrawingArea.setBackgroundColor(Color.GREEN);
}
}
查看Class
public class RandomShapeView extends View {
Paint paint;
public RandomShapeView(Context context) {
super(context);
paint = new Paint();
paint.setColor(Color.BLACK);
}
@Override
protected void onDraw(Canvas canvas) {
}
}
布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">
<Button
android:id="@+id/button"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<View
class="com.examples.danilofernandes.canvasonrelativelayout.RandomShapeView"
android:id="@+id/drawing_area"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
Z 顺序隐含在元素在 XML 中出现的顺序中。换个地方,应该没问题。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MyActivity">
<com.examples.danilofernandes.canvasonrelativelayout.RandomShapeView
android:id="@+id/drawing_area"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<Button
android:id="@+id/button"
android:text="@string/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>