Skip to content

Instantly share code, notes, and snippets.

View alohaabhi's full-sized avatar

Abhishek Jangra alohaabhi

View GitHub Profile
val inflater: LayoutInflater = LayoutInflater.from(this)
val newView = inflater.inflate(R.layout.new_view, rootView, attachToRoot)
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val rootView: ViewGroup = findViewById(R.id.activity_main)
val inflater = LayoutInflater.from(this)
val red = inflater.inflate(R.layout.rectangle, rootView, true)
val lime = inflater.inflate(R.layout.rectangle, rootView, false)
lime.setBackgroundColor(ContextCompat.getColor(this, R.color.lime))
rootView.addView(lime)
rootView.removeViewInLayout(red)
rootView.removeViewInLayout(lime)
CustomPaint(
painter: DrawCircle(getRandomColor(), 80.0),
);
class DrawCircle extends CustomPainter {
Paint circlePaint;
final radius;
DrawCircle(Color color, this.radius) {
this.circlePaint = Paint()
..color = color
..style = PaintingStyle.fill;
}
@override
void paint(Canvas canvas, Size size) {
GestureDetector(
child: Circle(getRandomColor(), circleState),
onTap: onCircleTap,
)
);
void onCircleTap() {
circleState.currentState.setColor(getRandomColor());
}
CustomPaint(
size: Size(CIRCLE_RADIUS * 2, CIRCLE_RADIUS * 2),
painter: DrawCircle(color, CIRCLE_RADIUS),
);
CustomPaint(
size: Size(CIRCLE_RADIUS, CIRCLE_RADIUS),
painter: DrawCircle(color, CIRCLE_RADIUS)
);
ClipRect(
child: CustomPaint(
size: Size(CIRCLE_RADIUS, CIRCLE_RADIUS),
painter: DrawCircle(color, CIRCLE_RADIUS)
)
);