This shows you the differences between two versions of the page.
mdad:laboratoare:03 [2020/11/18 17:06] ioana_maria.culic |
mdad:laboratoare:03 [2020/11/18 17:24] (current) ioana_maria.culic |
||
---|---|---|---|
Line 2: | Line 2: | ||
**LinearLayout**\\ | **LinearLayout**\\ | ||
LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the __android:orientation__ attribute.\\ | LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the __android:orientation__ attribute.\\ | ||
- | LinearLayout has one goal in life: lay out children in a single row or column (depending on if its android:orientation is horizontal or vertical).\\ | + | LinearLayout has one goal: lay out children in a single row or column (depending if the android:orientation is horizontal or vertical).\\ |
- | Another Layouts: RelativeLayout, FrameLayout, GridLayout, CoordinatorLayout etc\\ | + | Other Layouts: RelativeLayout, FrameLayout, GridLayout, CoordinatorLayout etc\\ |
\\ | \\ | ||
{{:dapm:laboratoare:linearlayout_vs_relativelayout.png?600|}} | {{:dapm:laboratoare:linearlayout_vs_relativelayout.png?600|}} | ||
Line 9: | Line 9: | ||
\\ | \\ | ||
**Fill_parent**(renamed **MATCH_PARENT** in API Level 8 and higher) vs **Wrap_content** \\ | **Fill_parent**(renamed **MATCH_PARENT** in API Level 8 and higher) vs **Wrap_content** \\ | ||
- | - Setting the layout of a widget to __fill_parent__ will force it to expand to take up as much space as is available within the layout element it's been placed in. It's roughly equivalent of setting the dockstyle of a Windows Form Control to Fill.\\ | + | - Setting the layout of a widget to __fill_parent__ will force it to expand to take up as much space as available within the layout element it's been placed in. It's the rough equivalent to setting the dockstyle of a Windows Form Control to Fill.\\ |
- Setting a View's size to __wrap_content__ will force it to expand only far enough to contain the values (or child controls) it contains. For controls -- like text boxes (TextView) or images (ImageView) -- this will wrap the text or image being shown.\\ | - Setting a View's size to __wrap_content__ will force it to expand only far enough to contain the values (or child controls) it contains. For controls -- like text boxes (TextView) or images (ImageView) -- this will wrap the text or image being shown.\\ | ||
\\ | \\ | ||
Line 16: | Line 16: | ||
\\ | \\ | ||
**Difference Between OnClickListener vs OnClick:**\\ | **Difference Between OnClickListener vs OnClick:**\\ | ||
- | __OnClickListener__ is what waits for someone to actually click, __onclick__ determines what happens when someone clicks\\ | + | __OnClickListener__ is what waits for someone to actually click on the element while __onclick__ determines what happens after the click\\ |
- | An OnClickListener enable you to separate the action/behavior of the click event from the View that triggers the event. \\ | + | An OnClickListener enables you to separate the action/behavior of the click event from the View that triggers the event. \\ |
Since OnClickListener is an interface, the class that implements it has flexibilities in determining the instance variables and methods that it needs in order to handle the event.\\ | Since OnClickListener is an interface, the class that implements it has flexibilities in determining the instance variables and methods that it needs in order to handle the event.\\ | ||
\\ | \\ | ||
- | Lately android added a xml attribute to views called android:onclick, that can be used to handle clicks directly in the view's activity without need to implement any interface.\\ | + | Lately, android added a xml attribute to views called android:onclick, that can be used to handle clicks directly in the view's activity without the need to implement any interface.\\ |
- | The onClick with function binding in XML Layout is a binding between onClick and the function that it will call. The function have to have one argument (the View) in order for onClick to function. | + | The onClick function binding in XML Layout is a binding between onClick and the function that it calls. The function needs to have one argument (the View) in order for onClick to function. |
//example :// \\ | //example :// \\ | ||
Line 61: | Line 61: | ||
- | ====== Exercises : ====== | + | ====== Exercises ====== |
- | **Ex 1** A) Make a new app. Transform the layout into a LinearLayout with __orientation vertical__. \\ | + | **Ex 1** A) Create a new app. Transform the layout into a LinearLayout with __orientation vertical__. \\ |
- | B) Make two Buttons with __width match_parent__ and __height wrap_content__.\\ | + | B) Add two Buttons with __width match_parent__ and __height wrap_content__.\\ |
- | On click the first one must show messages using the __Toast__. \\ | + | On click the first one should show a message using the __Toast__. \\ |
For the first button use the **android:onClick="push"** – with __push function__ \\ | For the first button use the **android:onClick="push"** – with __push function__ \\ | ||
Line 73: | Line 73: | ||
Toast.makeText(this, "You pushed the button from push function", Toast.LENGTH_SHORT).show(); | Toast.makeText(this, "You pushed the button from push function", Toast.LENGTH_SHORT).show(); | ||
- | **Ex 2** In onCreate function, write logs (Verbose, Debug, Info, Warning, Error). | + | **Ex 2** In the onCreate function, write logs (Verbose, Debug, Info, Warning, Error). |
- | View them with Logcat (The Logcat window in Android Studio displays system messages, such as when a garbage collection occurs.\\ | + | View them using Logcat (The Logcat window in Android Studio displays system messages, such as when a garbage collection occurs.\\ |
It displays messages in real time and keeps a history so you can view older messages)\\ | It displays messages in real time and keeps a history so you can view older messages)\\ | ||
- | The **tag** of a system log message is a short string indicating the system component from which the message originates. | + | The **tag** of a system.log message is a short string indicating the system component from which the message originates. |
Logcat message format : Log.d(tag, message) | Logcat message format : Log.d(tag, message) | ||
- | **Ex 3** Do an activity overwritten by the following event features. Display a log message with the Event Tag in each of these features. The log message text must contain the name of the event.\\ | + | **Ex 3** Create an activity overwritten by the following event features. Display a log message with the Event Tag in each of these features. The log message text must contain the name of the event.\\ |
For example, in onCreate() you can display a text message called onCreate (). | For example, in onCreate() you can display a text message called onCreate (). | ||