The question is: there is draw_activity
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFF" android:orientation="vertical"> <com.example.android.threepointscircle.DrawActivity.DrawView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/drawView"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:id="@+id/backButton" android:text="back" /> </RelativeLayout>
Have DrawActivity
public class DrawActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new DrawView(this)); Button backButton = (Button) findViewById(R.id.backButton); backButton.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View view) { /** ΠΠ½ΡΠ΅Π½Ρ Π΄Π»Ρ ΠΏΠ΅ΡΠ΅Ρ
ΠΎΠ΄Π° Π½Π° ΡΠΊΡΠ°Π½ Π²Π²ΠΎΠ΄Π° ΡΠΎΡΠ΅ΠΊ */ Intent drawActivity = new Intent(DrawActivity.this, MainActivity.class); startActivity(drawActivity); } }); }
In DrawView
circle at a given point. Under it, I want to make a return button to activate, where the coordinates of points are initially entered. It is impossible neither to see the button, nor to initialize it.
What am I doing wrong, can someone tell me how best to create a button on a Canvas
?
DrawView class with a constructor (methods and onDraw do not show, they work, checked)
//ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΡΠ΅ ΠΊΠ»Π°ΡΡΠ° DrawActivity public int width; public int height; public float cx; public float cy; public float[] coordinates; class DrawView extends View { /** ΠΠ°Π΄Π°Π΅ΠΌ ΠΏΠ΅ΡΠ΅ΠΌΠ΅Π½Π½ΡΠ΅ ΠΊΠ»Π°ΡΡΠ° * Ρ - ΠΊΠΈΡΡΡ Π΄Π»Ρ ΡΠΈΠ³ΡΡ * ΡΠ’ - ΠΊΠΈΡΡΡ Π΄Π»Ρ ΡΠ΅ΠΊΡΡΠ° * rectF - ΡΠ°ΠΌΠΊΠ° Π΄Π»Ρ ΠΏΠΎΠ΄ΠΏΠΈΡΠ΅ΠΉ ΡΠΎΡΠ΅ΠΊ * radius - ΡΠ°Π΄ΠΈΡΡ ΠΎΠΊΡΡΠΆΠ½ΠΎΡΡΠΈ * tk - ΠΊΠΎΡΡΡΠΈΡΠΈΠ΅Π½Ρ ΠΎΡΠ½ΠΎΡΠ΅Π½ΠΈΡ Π΄Π»ΠΈΠ½Ρ ΠΏΠΎΠ»ΠΎΠ²ΠΈΠ½Ρ ΡΠΊΡΠ°Π½Π° ΠΊ ΡΠ°Π΄ΠΈΡΡΡ ΠΎΠΊΡΡΠΆΠ½ΠΎΡΡΠΈ */ Paint p; Paint pT; Rect rect; RectF rectF; float radius, tk; public DrawView(Context context) { super(context); Intent intent = getIntent(); p = new Paint(); pT = new Paint(); rectF = new RectF(); //ΠΏΠΎΠ»ΡΡΠ΅Π½ΠΈΠ΅ ΡΠΈΡΠΈΠ½Ρ ΠΈ Π²ΡΡΠΎΡΡ ΡΠΊΡΠ°Π½Π° initWidthAndHeight(context); cx = intent.getFloatExtra("cx", 0); cy = intent.getFloatExtra("cy", 0); coordinates = intent.getFloatArrayExtra("coord"); // ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌ ΡΠ°Π΄ΠΈΡΡ ΠΎΠΊΡΡΠΆΠ½ΠΎΡΡΠΈ getDistance(); // ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌ ΠΊΠΎΡΡΡΠΈΡΠΈΠ΅Π½Ρ ΡΠΎΠΎΡΠ½ΠΎΡΠ΅Π½ΠΈΡ ΡΠΈΡΠΈΠ½Ρ ΡΠΊΡΠ°Π½Π° ΠΊ ΡΠ°Π΄ΠΈΡΡΡ ΠΎΠΊΡΡΠΆΠ½ΠΎΡΡΠΈ tk = (float) 0.8 * ((width / 2) / radius); }