我是Android新手,我想在固定位置绘制3个圆圈。
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ImageView imgCircle = (ImageView) findViewById(R.id.imgCircle);
final ImageView imgCircle1 = (ImageView) findViewById(R.id.imgCircle1);
final ImageView imgCircle2 = (ImageView) findViewById(R.id.imgCircle2);
//first
Paint paint = new Paint();
paint.setColor(Color.BLUE);
paint.setStyle(Paint.Style.STROKE);
paint.setStyle(Paint.Style.FILL);
paint.setAlpha(50);
Bitmap bmp = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bmp);
canvas.drawCircle(bmp.getWidth()/2, bmp.getHeight()/2, 150, paint);
imgCircle.setImageBitmap(bmp);
(第二个和第三个圆圈的代码与第一个圆圈相同)
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.andav.wisersteps_v2.MainActivity"
android:background="@drawable/foot">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@mipmap/ic_launcher"
android:id="@+id/imgCircle2"
tools:ignore="ContentDescription"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="34dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@mipmap/ic_launcher"
android:id="@+id/imgCircle1"
tools:ignore="ContentDescription"
android:layout_marginTop="21dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/imgCircle2"
android:layout_toEndOf="@+id/imgCircle2"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@mipmap/ic_launcher"
android:id="@+id/imgCircle"
tools:ignore="ContentDescription"
android:layout_marginTop="53dp"
android:layout_below="@+id/imgCircle1"
android:layout_alignLeft="@+id/imgCircle1"
android:layout_alignStart="@+id/imgCircle1" />
</RelativeLayout>
问题是main_activity位置(我想绘制圆圈的位置)与模拟器位置不匹配: before && after
我该如何解决这个问题?