This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val inflater: LayoutInflater = LayoutInflater.from(this) | |
| val newView = inflater.inflate(R.layout.new_view, rootView, attachToRoot) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val lime = inflater.inflate(R.layout.rectangle, rootView, false) | |
| lime.setBackgroundColor(ContextCompat.getColor(this, R.color.lime)) | |
| rootView.addView(lime) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rootView.removeViewInLayout(red) | |
| rootView.removeViewInLayout(lime) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CustomPaint( | |
| painter: DrawCircle(getRandomColor(), 80.0), | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| GestureDetector( | |
| child: Circle(getRandomColor(), circleState), | |
| onTap: onCircleTap, | |
| ) | |
| ); | |
| void onCircleTap() { | |
| circleState.currentState.setColor(getRandomColor()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CustomPaint( | |
| size: Size(CIRCLE_RADIUS * 2, CIRCLE_RADIUS * 2), | |
| painter: DrawCircle(color, CIRCLE_RADIUS), | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CustomPaint( | |
| size: Size(CIRCLE_RADIUS, CIRCLE_RADIUS), | |
| painter: DrawCircle(color, CIRCLE_RADIUS) | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ClipRect( | |
| child: CustomPaint( | |
| size: Size(CIRCLE_RADIUS, CIRCLE_RADIUS), | |
| painter: DrawCircle(color, CIRCLE_RADIUS) | |
| ) | |
| ); |
OlderNewer