Winter vacation learning progress 1 (Android configuration environment and hello world)

Today's Learning Content: Watched the Android teaching video on Belly Mile to get a brief understanding of the basic kno...

Today's Learning Content: Watched the Android teaching video on Belly Mile to get a brief understanding of the basic knowledge of Android

Specific content:

1. Configure the Android Development Environment (install Android studio, configure JDK)

Android studio is an integrated environment that works without having to configure JDK. If you want to configure JDK, you can refer to the following tutorials.

JDK Configuration Tutorial Link: https://blog.csdn.net/siwuxie095/article/details/53386227

Reference link for Android studio installation tutorial: https://blog.csdn.net/xuw_xy/article/details/89524335

2. Running the first helloworld and understanding of the simple directory

Simple Understanding of Some Catalogs of the Android Project

AndoridManifest.XML Places a global layout file

Java code and Android test files are placed under the Java directory, and MainActivity.java files are mainly used to write Java code

The res directory places the resource directory: drawable places the picture resource, but it is less commonly used, where the picture can be scaled.Under the layout directory is the main active XML file that is used to lay out the interface.mipmap is mainly used to place picture resources, and the resolution of the picture can be flexibly selected.The colors directory under the values directory is used to place color resources, strings are used to place string resources, and style s are used to place interface theme resources.

3. Three ways to control UI interface and customize View:XML, JAVA, JAVA&XML

java is more flexible, but it writes more code and has a simple XML layout, which combines and uses the most.

Reference to the code to write a rabbit to follow the mouse movement

activity_main.xml

<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@mipmap/background" android:id="@+id/bac" tools:context=".MainActivity"> </FrameLayout>

RabbitView.java

package com.itheima.myview; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.view.View; public class RabbitView extends View { public float bitmapX; public float bitmapY; public RabbitView(Context context) { super(context); bitmapX=290; bitmapY=130; } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); Paint paint=new Paint(); Bitmap bitmap= BitmapFactory.decodeResource(this.getResources(), R.mipmap.rabbit); canvas.drawBitmap(bitmap,bitmapX,bitmapY,paint); if(bitmap.isRecycled()){ bitmap.isRecycled(); } } }

MainActivity.java

package com.itheima.myview; import android.os.Bundle; import android.view.MotionEvent; import android.view.View; import android.widget.FrameLayout; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); FrameLayout frameLayout=(FrameLayout)findViewById(R.id.bac); final RabbitView rabbit=new RabbitView(this); rabbit.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { rabbit.bitmapX=event.getX(); rabbit.bitmapY=event.getY(); rabbit.invalidate(); return true; } });frameLayout.addView(rabbit); } }

Run screenshots:

1 February 2020, 12:10 | Views: 5228

Add new comment

For adding a comment, please log in
or create account

0 comments