我尝试使用画布绘制棋盘,但视图恢复了所有实体并且看不到我的 activitymain xml 按钮
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/area"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/back"
tools:context=".MainActivity">
<Button
android:id="@+id/buttonnew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginStart="6dp"
android:layout_marginTop="2dp"
android:background="@drawable/buttonnewgradient"
android:text="@string/Buttonnewtext"
android:textColor="#dde41c"
android:textSize="18sp" />
</RelativeLayout>
public class BoardClass extends View {
public BoardClass(Context context)
{ super(context);}
}
mainactivity.java
public class MainActivity extends AppCompatActivity {
BoardClass board;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
board = new BoardClass(this);
setContentView(board);
}
}
牧羊人nacy
相关分类