Common layout Relative Layout relativelayout
- Component default left-aligned, top-aligned
Sets the component to the right of the specified component
android:layout_toRightOf="@id/tv1"
Sets the bottom of the specified component
android:layout_below="@id/tv1"
Set the right-justified parent element
android:layout_alignParentRight="true"
Sets the right alignment to the specified component
android:layout_alignRight="@id/tv1"
Linear layout LinearLayout
Specify the arrangement direction of each node
android:orientation="horizontal"
Set Right alignment
android:layout_gravity="right"
- When vertical layout, only left and right align and center horizontally, top bottom alignment Vertical Center invalid
- When horizontal layout, only top bottom is aligned and centered vertically
- When using match_parent, be careful not to put the other components out
A very important attribute of linear layout: weights
android:layout_weight="1"
- The weights are set to proportionally allocate the remaining space
Frame Layout Framelayout
Table Layout Tablelayout
- Each node is a row, and each of its child nodes is a column
The nodes in the table layout can not be set to a wide height because the settings are also invalid
- The child node width of the root node matches the parent element, and the content of the package is high
- The node's child node width is the parcel content, the content of the parcel is high
- The above default properties cannot be modified
The following properties can be set in the root node, which means that the 1th column stretches to fill the remaining space of the screen width
android:stretchColumns="1"
Absolute layout absolutelayout
directly specifies the x, y coordinates of the component
android:layout_x="144dp"android:layout_y="154dp"
Logcat
- Total log information is divided into 5 levels
- Verbose
- Debug
- Info
- Warn
- Error
- Define filters for easy viewing
- The log level of the System.out.print output is Info,tag is System.out
Log output API provided by Android
Log.v(TAG, "加油吧,童鞋们");Log.d(TAG, "加油吧,童鞋们");Log.i(TAG, "加油吧,童鞋们");Log.w(TAG, "加油吧,童鞋们");Log.e(TAG, "加油吧,童鞋们");
File read and write operations
- RAM memory: Running memory, equivalent to the computer's memory
- ROM Memory: Internal storage space, equivalent to the computer's hard disk
- SD card: External storage space, equivalent to the computer's mobile hard disk
Read and write files in the internal storage space
Small case: User input account password, tick "Remember account password", click the login button, log in while persistent save account and password
1. Define Layout 2. Click event to complete the button
Pop toast Prompt User login success
Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
3. Get the data entered by the user
4. Enable IO stream to write files to internal storage
Directly open file output stream write data
//持久化保存数据 File file = new File("data/data/com.itheima.rwinrom/info.txt"); FileOutputStream fos = new FileOutputStream(file); fos.write((name + "##" + pass).getBytes()); fos.close();
Detect if the file exists before reading the data
if(file.exists())
Read the saved data, also directly open the file input stream read
File file = new File("data/data/com.itheima.rwinrom/info.txt");FileInputStream fis = new FileInputStream(file);//把字节流转换成字符流BufferedReader br = new BufferedReader(new InputStreamReader(fis));String text = br.readLine();String[] s = text.split("##");
After reading to the data, echo back to the input box
et_name.setText(s[0]);et_pass.setText(s[1]);
- The app can only create files in its own package, can't go to other people's homes to create
Copy items directly
- Where changes are needed:
- Project name
- App Package Name
- R file re-guide package
Read and write files using the path API
- Getfilesdir () The path to the resulting file object is Data/data/com.itheima.rwinrom2/files
- Files stored in this path, as long as you do not delete, it has been in
Getcachedir () The path to the resulting file object is Data/data/com.itheima.rwinrom2/cache
- Files stored under this path may be deleted when memory is low
The System Management application interface clears the cache, clears the contents of the cache folder, clears the data, and clears the entire package.
The path to the external storage of the read-write Data SD card
- SD card path prior to sdcard:2.3
- SD card path prior to mnt/sdcard:4.3
SD card path after storage/sdcard:4.3
The simplest way to open an SD card
File file = new File("sdcard/info.txt");
Write SD card requires permission
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
Read SD card, do not need permission before 4.0, 4.0 can be set to need
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Use API to get the real path of SD card, some phone brands will change the path of SD card
Environment.getExternalStorageDirectory()
Determine if the SD card is ready
if(Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED))
View source code find code to get the remaining capacity of SD card
- Import Settings Project
Find "free space" to get
<string name="memory_available" msgid="418542433817289474">"可用空间"</string>
Find "memory_available" and get
<Preference android:key="memory_sd_avail" style="?android:attr/preferenceInformationStyle" android:title="@string/memory_available" android:summary="00"/>
Find "MemorySDavail" to get
//这个字符串就是sd卡剩余容量formatSize(availableBlocks * blockSize) + readOnly//这两个参数相乘,得到sd卡以字节为单位的剩余容量availableBlocks * blockSize
The storage device is divided into chunks, each with a fixed size
- Chunk Size * Number of chunks equals the total size of the storage device
Access rights to Linux files
- In Android, each app is a standalone user
- Drwxrwxrwx
- 1th bit: D represents a folder,-represents a file
- 第2-4位: rwx, which indicates the owner user (owner) of this file has permission to the file
- R: Read
- W: Write
- X: Execute
- 第5-7位: Rwx, which represents the permissions of the user (grouper) in the same group as the file owner user
- 第8-10位: rwx, which indicates that the user (other) of another user group has permission to the file
Four modes of Openfileoutput
- MODE_PRIVATE:-RW-RW----
- MODE_APPEND:-RW-RW----
- MODEWorld writeable:-rw-rw--w-
- MODEWorld readable:-rw-rw-r--
Sharedpreference
Store your account password with sharedpreference
Write data to Sharedpreference.
//拿到一个SharedPreference对象SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE);//拿到编辑器Editor ed = sp.edit();//写数据ed.putBoolean("name", name);ed.commit();
Fetch data from Sharedpreference.
SharedPreferences sp = getSharedPreferences("config", MODE_PRIVATE);//从SharedPreference里取数据String name = sp.getBoolean("name", "");
Accompanying notes linear layout
- When the orientation is vertical, the horizontal coordinate setting takes effect and the vertical direction does not take effect.
- When the direction is horizontal, opposite the above
Weight
- Proportionally distributes the remaining space on the screen
- Weights are best paired with 0DP
Read and write file ROM memory in Android system: Storage memory
- Equivalent to a computer's hard drive
- Internal storage space Internal storage
SD card:
- The equivalent of a computer's mobile hard drive
- External storage space External storage
SD card Status
Remove: No plug-in SD card UNMOUNT:SD card is plugged in, but no Mount CHECKING:SD card is being traversed by the system MOUNTED:SDcard can read and write mounted read ONLY:SD card is available, but read only
Get the remaining capacity of the SD card
- Chunk size
- Total number of blocks
- Number of available chunks
- Chunk Size * Total number of chunks = total size of the storage device
- Chunk Size * Number of available chunks = available size of storage device
File access Permissions
D rwx rwx rwx
Other great article articles
jquery Tutorials (9)-dom tree Operations copy elements Android learning note (Android Alertdialog) create List dialog [2]android sharesdk SSO login Sina and MySQL Index type in detail-b-tree index broadcastreceiver use the Alertdialog after the app crashes
More about Android development articles
Data storage and interface presentation based on Android application development (II.)