我必须在横幅下方绘制一个自定义视图,就像附加的PICK
一样在DaTTab横幅下面我必须绘制矩形视图my xml
- main.xml
醇>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relative_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<include android:id="@+id/banner" layout="@layout/upper_border" />
<com.example.ui_1.Border_Portrait
android:id="@+id/custom_display_view1"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_below="@+id/banner"
/>
Draw_Border.jav
class Border_Portrait extends View{
private static final int DEFAULT_SIZE = 100;
int mViewHeight , mViewWidth ;
Paint mPaint ;
Canvas mCanvas ;
int margin ;
float [] mPoints ;
int mLogoHeight ;
int mLogoWidth ;
int dy,dx ;
public Border_Portrait(Context context) {
super(context);
}
public Border_Portrait(Context context, AttributeSet attrs) {
super(context, attrs);
margin = 7 ;
mPaint = new Paint();
mPaint.setColor(Color.rgb(0,188,226));
mPaint.setStrokeWidth(3);
mLogoHeight = ScreenUtils.convertDIPToPixels(getContext(), 50 + margin );
mLogoWidth = ScreenUtils.convertDIPToPixels(getContext(), 66 + margin);
dy = ScreenUtils.convertDIPToPixels(getContext(),1) ;
dx= ScreenUtils.convertDIPToPixels(getContext(),1) ;
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.save();
mPoints = new float [] {
margin + mLogoWidth ,margin,//1
getWidth()-margin ,margin ,//1
getWidth()-margin ,margin ,//2
getWidth()-margin , getHeight()-margin ,//2
getWidth()-margin , getHeight()-margin , //3
margin , getHeight()-margin , //3
margin , getHeight() - margin , //4
margin , mLogoHeight + dy ,//4
margin , mLogoHeight + dy , // 5
margin + mLogoWidth + dx ,mLogoHeight + dy, //5
margin + mLogoWidth ,mLogoHeight + dy, //6
margin + mLogoWidth ,margin, //6
} ;
canvas.drawLines(mPoints, mPaint);
canvas.restore();
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int parentWidth = MeasureSpec.getSize(widthMeasureSpec);
int parentHeight = MeasureSpec.getSize(heightMeasureSpec);
this.setMeasuredDimension(parentWidth, parentHeight);
}
private int calculateMeasure(int measureSpec) {
return 0 ;
}
}
我的问题是如何在我参考的运行时测量边框的宽度
和其他链接,但直到现在没有运气
答案 0 :(得分:0)
刚刚在main.xml中添加了边距
<com.example.ui_1.Border_Portrait
android:id="@+id/custom_display_view1"
android:layout_marginTop="50dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>