Class Dimension for java on android

前端 未结 3 1451
别那么骄傲
别那么骄傲 2020-12-10 16:16

What is the equivalent form of class java.awt.Dimension for android?

3条回答
  •  既然无缘
    2020-12-10 16:58

    Why do you need to abuse other classes instead of implementing something extremely simple like:

    public class Dimensions {
    
        public int width;
        public int height;
    
        public Dimensions() {}
    
        public Dimensions(int w, int h) {
            width = w;
            height = h;
        }
    
        public Dimensions(Dimensions p) {
            this.width = p.width;
            this.height = p.height;
        }
    
        public final void set(int w, int h) {
            width = w;
            height = h;
        }
    
        public final void set(Dimensions d) {
            this.width = d.width;
            this.height = d.height;
        }
    
        public final boolean equals(int w, int h) {
            return this.width == w && this.height == h;
        }
    
        public final boolean equals(Object o) {
            return o instanceof Dimensions && (o == this || equals(((Dimensions)o).width, ((Dimensions)o).height));
        }
    
    }
    

提交回复
热议问题