Talk Android together (the 132nd time: Android custom view 9)

Hello, everyone. Last time we talked about the example of custom view in Android. This time we continue to talk about this example. Don't talk about gossip. Let's get to the point. Let's talk Android together!

Ladies and gentlemen, this time we started to define the view by ourselves. As before, we explained it by combining text with code.

public class DIYView extends View {}

public class DIYView extends View {

   public DIYView(Context context) {
       super(context);
   }

   public DIYView(Context context, AttributeSet attrs) {
       super(context, attrs);
   }

   public DIYView(Context context, AttributeSet attrs, int defStyleAttr) {
       super(context, attrs, defStyleAttr);
   }

   public DIYView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
       super(context, attrs, defStyleAttr, defStyleRes);
   }

   @Override
   protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
       super.onMeasure(widthMeasureSpec, heightMeasureSpec);
   }

   @Override
   protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
       super.onLayout(changed, left, top, right, bottom);
   }

   @Override
   protected void onDraw(Canvas canvas) {
       super.onDraw(canvas);
   }
}

    <com.example.talk8.tetest.DIYView
       android:id="@+id/diy_view"
       android:layout_height="200dp"
       android:layout_width="300dp"
    />

As you can see from the code, we just set up a framework, and the specific content will be explained in later chapters.

Ladies and gentlemen, let's stop here about the example of custom view in androd. For more examples, listen to the next chapter!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>