Reputation: 6302
I have a custom imageView, say MyImageView class and i am trying to draw some lines above it.
public class MyImageView extends ImageView
{
public MyImageView(Context context) {
super(context);
invalidate();
// TODO Auto-generated constructor stub
}
public MyImageView(Context context, AttributeSet attrs) {
super(context, attrs);
invalidate();
}
public MyImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
invalidate();
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setColor(Color.BLACK);
canvas.drawLine(0, 0, 100, 100, p);
canvas.drawLine(0, 0, 20, 20, p);
canvas.drawLine(20, 0, 0, 20, p);
super.onDraw(canvas);
}
}
In my activity class i have set an image to that custom imageView with the help of a bitmap.
MyImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView=(MyImageView)findViewById(R.id.image);
Bitmap dbitmap = BitmapFactory.decodeResource(getResources(), R.drawable.dinkan);
Bitmap bitmap = dbitmap.copy(Bitmap.Config.ARGB_8888, true);
imageView.setImageBitmap(bitmap);
imageView.invalidate();
}
So now the problem is, the lines are drawn under the image so that i cannot see it. I want the lines to be drawn over the image. How should i implement it?
Upvotes: 4
Views: 1579
Reputation: 617
You can add a Horizontal line by creating view like this
<View
android:id="@+id/line_77"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_below="@+id/relativeLayout8"
android:layout_marginTop="5dp" />
Upvotes: 0
Reputation: 1715
Try writing the canvas.drawLine()
code below the super.onDraw(canvas)
. This means that first the imageview's default implementation will happen and after that the custom implementation i.e., the line will be drawn.
Upvotes: 2