Android UI Interface Design - with Reference Documents
- UI Interface Design
- 1. Basic Components
- 1. Text class components
- 2. Button class components
- 2.1 Button, a common button component (a subclass of the textview component)
- 2.1.1 Button Events - Common Listeners
- 2.2 Picture Button ImageButton Component
- 2.3 RadioButton Component
- 2.3.1 Add Selection Change Event
- 2.4 Checkbox CheckBox Component
- 3. Date Time Class Components
- 2. Advanced Components
UI Interface Design
1. Basic Components
1. Text class components
The feature is to display text information in the interface
1.1 TextView
Reference Document docs
attribute | Interpretation | Explain |
---|---|---|
textSize | Text Size Properties | Unit: sp |
textColor | Text color | Attribute values: 1. Can be displayed in the left preview of AS 2. Click on the preview icon to adjust the color display |
maxWidth | Maximum width | Unit: dp |
layout_marginBottom | Bottom Outer Margin | Should be the property value of Layout Manager |
layout_width | Typically wrap_content | ViewGroup.LayoutParams Properties |
layout_height | Typically wrap_content |
1.2 EditText (a subclass of the textview component)
attribute | Interpretation | Explain |
---|---|---|
layout_width | wide | Typically match_parent |
layout_height | high | Typically wrap_content |
hint | Prompt message | EditText is very common |
inputType | Set password textPassword-Number-Date, etc. | docs |
drawableLeft | Draw an image to the left of the text | docs |
android:drawablePadding | Draw the spacing between the image and the text | Use in combination |
lines | Number of rows in the edit box, special: scrolling display over the number of rows | docs |
2. Button class components
2.1 Button, a common button component (a subclass of the textview component)
2.1.1 Button Events - Common Listeners
What is a listener
- Set up listeners for components
- Actions that trigger the listener (user)
- Code to execute
Two ways to add event listeners in AS
- Anonymous internal class as click event listener
- Implemented through the onClick property
2.1.1.1 Event Listener Steps:
-
Setting component ID in XML
-
Create component objects and findViewById (R.id. [string]) initialize
-
Component object calls setOnClickListener(new View.OnClickListener(){
@override
......
})
-
For example, add the message prompt box Toast.makeText(this, "single button"), Toast.LENGTH_SHORT).show();
2.1.1.2onClick attribute steps:
- Write a method in Activity that contains parameters of type View
- android:onClick="Method name of step 1"
2.2 Picture Button ImageButton Component
Same:
- All onClick events can start on a single machine
Difference:
- ImageButton has no text property
attribute | Interpretation | Explain |
---|---|---|
src | Picture Resource Properties | Under @mipmap/file |
background | background | Set background value to'#0000', background is transparent, avoid gray |
2.3 RadioButton Component
Use nested with tags
2.3.1 Add Selection Change Event
setOnCheckedChangeListener(new RadioGroup)
- Get RadioGroup Object Call
- Object calls setOnCheckedChangeListener method
- Newa RadioGroup.OnCheckedChangeListener listener
- Override Abstract methods, remark here on anonymous internal classes Detailed Connection
- Toast Tip Box
2.4 Checkbox CheckBox Component
- Check function
- Diagram Diagram
- Subclasses of Button
- Label wrapping doesn't need to be used like RaidoGroup
3. Date Time Class Components
Date Picker: Reference Documents
Time Picker - Reference Document
Timer Chronometer - Reference Document
2. Advanced Components
1. Progress Bar Class Component
1.1 ProgressBar
Real-time accuracy - Determinate Progress
Loading - Indeterminate Progress
attribute | Interpretation | Explain |
---|---|---|
style | Progress Bar Type | Six types of Widget.ProgressBar.Horizontal; Widget.ProgressBar.Small; Widget.ProgressBar.Large; Widget.ProgressBar.Large; Widget.ProgressBar.Small.Inverse |
Or theme property value: android:attr/progressBarStyleHorizontal | ||
max | Maximum | Define a maximum value, for example, 100 |
progress | Speed of progress | For example: 50 |
Threads - Flowcharts Step 1: Determine whether it is completed or not, step 2 or step 3; Step 2: Call the setProgress() method to update the progress and return to step 1 Step 3: Call the setVisibility() method to set the progress bar to not show, end
Knowledge Points:
- Label
- Set the full screen display when loading, getWindow()
- Message Processing as Component Update Subthread
- Create thread simulation progress handler
Layout file:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout 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/bg" tools:context=".MainActivity"> <ProgressBar android:id="@+id/progressBar" android:layout_width="match_parent" android:layout_height="wrap_content" tools:ignore="MissingConstraints" style="@android:style/Widget.ProgressBar.Horizontal" android:max="100" android:layout_alignParentBottom="true" android:layout_marginBottom="30dp" /> </RelativeLayout>
MainActivity.java
package com.ws.progressbardemo; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import android.annotation.SuppressLint; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.View; import android.view.WindowManager; import android.widget.ProgressBar; import android.widget.Toast; public class MainActivity extends Activity { private ProgressBar progressBar; private int mProgress=0; private Handler mhandler; @SuppressLint("HandlerLeak") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);//Set full screen display, cancel status fields such as signal at the top of the phone progressBar = findViewById(R.id.progressBar); mhandler = new Handler(){ @Override public void handleMessage(@NonNull Message msg) { //Processing message operations if(msg.what == 0x111){ progressBar.setProgress(mProgress); }else{ Toast.makeText(MainActivity.this, "Time-consuming operation completed", Toast.LENGTH_SHORT).show(); progressBar.setVisibility(View.GONE); } } }; //Create a trip simulation time-consuming operation new Thread(new Runnable() { @Override public void run() { while (true){ mProgress = doWork(); Message m = new Message(); if(mProgress<100){ m.what = 0x111;//Custom Message Code, //Time-consuming Operation Not Completed mhandler.sendMessage(m); }else{ m.what = 0x110;//Time-consuming operation completed mhandler.sendMessage(m); break; } } } private int doWork(){ mProgress += Math.random()*10; try { Thread.sleep(200); } catch (InterruptedException e) { e.printStackTrace(); } return mProgress; } }).start(); } }
1.2 SeekBar Drag Bar
Reference Document docs - Yes ProgressBar Subclasses
attribute | Interpretation | Explain |
---|---|---|
android:thumb | Draw your thumb on the search bar. | You can refer to another resource as'', or you can refer to topic properties as''.@[+][package:]type/name?[package:]type/name |
1.3 RatingBar Rating Comment Bar
Reference Document docs - Yes ProgressBar Subclasses
attribute | Interpretation | Explain |
---|---|---|
android:numStars | The number of stars (or rating items) to show. | Number of Stars |
android:rating | The rating to set by default. | |
android:stepSize | The step size of the rating. | 0.5 stars by default |
android:isIndicator | Can only see, can't modify |
2. Image Class Components
Mainly used to display pictures
2.1 ImageView
attribute | Interpretation | Explain |
---|---|---|
android:src | Sets a drawable as the content of this ImageView. | @drawable or@mipmap |
android:scaleType | Scale type | The default is equal scale scaling |
android:adjustViewBounds | Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable. | Set to true, adjust the component to wrap its own content, and set maxWidth and maxHeight to wrap the picture perfectly without exceeding its maximum width |
android:tint | To color | Similar mask |
2.2 Image Switcher ImageSwitcher
Image Switching + Animation Effects
`setInAnimation(Animation inAnimation)`
2.3 Grid View GridView
1. Add a picture resource and cannot pass an attribute (src)
2. Adapter Adapter: An interface connecting back-end data to front-end display, an important link between data and UI components
3. Where the data source can be ArrayList and Cursor
Four adapters:
- ArrayAdapter
- SimpleAdapter
- SimpleCursorAdapter: Database content is presented as a list
- BaseAdapter: Customizable
Note: Creating an adapter is complex
3. List Class Components
3.1 Dropdown List Spinner
- Drop-down options can be specified through the android:entries property and XML array resources
- Specify the adapter setAdapter () method
3.2 List View ListView
For example: WeChat Friends Directory
- Add ListView Component
- Create a LinearLayout layout file and set ImageView and TextView tag parameters
- Create an adapter under Avtivity to pass parameters
- Set up the adapter and output the status bar
Main_Activity.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/imageView" android:paddingTop="10dp" android:paddingBottom="10dp" android:paddingStart="10dp" android:paddingEnd="10dp" android:maxWidth="80dp" android:maxHeight="80dp" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <TextView android:id="@+id/textView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:layout_gravity="center"/> </LinearLayout>
MainActivity.java
package com.ws.listview; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; import android.widget.SimpleAdapter; import android.widget.Toast; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.ListIterator; import java.util.Map; import java.util.SimpleTimeZone; public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); int[] imageid = new int[]{R.drawable.img01,R.drawable.img02,R.drawable.img03,R.drawable.img04, R.drawable.img05,R.drawable.img06,R.drawable.img07,R.drawable.img08, R.drawable.img09,R.drawable.img10,R.drawable.img11,R.drawable.img12}; String[] titleid = new String[]{"Wang Yi","Wang Er","Wang San","Wong 4","Wong 5","Wong 6","Wong 7","Wong 8","Wong 9","Wong 10","Wong 11","Wong 12"}; List<Map<String,Object>> listitem = new ArrayList<>(); for (int i =0;i<imageid.length;i++){ Map<String,Object> map = new HashMap<>(); map.put("image",imageid[i]); map.put("title",titleid[i]); listitem.add(map); } SimpleAdapter simpleAdapter = new SimpleAdapter(this,listitem,R.layout.main, new String[]{"image","title"},new int[]{R.id.imageView,R.id.textView}); ListView listView = findViewById(R.id.listView); listView.setAdapter(simpleAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Map<String,Object> map = (Map<String, Object>) parent.getItemAtPosition(position); Toast.makeText(MainActivity.this, map.get("title").toString(), Toast.LENGTH_LONG).show(); } }); } }
3.3 ScrollView/HorizontalScrollView - very common
Vertical reference document docs,Horizontal reference document docs , two ways to add a scrolling view: in XML and in Java code
- Components are added normally, but be aware that you cannot have multiple subcomponents, so you can use them nested in the Layout Manager
- In Java code:
- Create a scroll view object using the construction method ScrollView
- Applying the addview method to add components to the scrolling view
- Add Scroll View to Layout Manager
4. Common Components
4.1 Tab
Reference Document docs
- Add TabHost, TabWidget, and TabContent components to the layout file
- Write a tab XML layout file
- Get and initialize the TabHost component
- weiTabHost Object Add Tab