A very common problem in development. The listview in the project is not just a simple text. You often need to define the listview yourself. Your own Adapter inherits the BaseAdapter and writes it in the adapter according to the requirements. Problems arise. Maybe It will happen that when you click on each item, there will be no response and focus cannot be obtained. The reason is mostly because there are sub-controls such as ImageButton, Button, CheckBox and other sub-controls (which can also be said to be sub-class controls of Button or Checkable) in the Item you define. At this time, these sub-controls will get the focus, so they often click What changes when it comes to item is the sub-control, and there is no response when clicking on the item itself.
At this time, you can use descendantFocusability to solve the problem. The API description is as follows:
android:descendantFocusability
Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.Must be one of the following constant values.
This attribute defines the relationship between the viewGroup and its child controls when a view gets focus.
There are three values for the attribute:
beforeDescendants: the viewgroup will give priority to its subclass controls and get the focus
## AfterDescendants: ViewGroup only gets the focus only when its subclasses do not need to get the focus
Atep.
## ###
Usually we use the third method, which is to add the attribute android:descendantFocusability="blocksDescendants" to the root layout of the Item layout.
android:layoutMode
Defines the layout mode of this ViewGroup.
Must be one of the following constant values.
##Constant
Value
Description
clipBounds
0
Use the children's clip bounds when laying out this container. Child control clipping bounds.
opticalBounds
1
Use the children's optical bounds when laying out this container. Subcontrol fiber boundary.
This corresponds to the global attribute resource symbol layoutMode.
##Related Methods
setLayoutMode( int)
android:paddingstart
##Android 4.1 (Jelly Bean) In TextView and EditText elements, set the "bidirectional" "Text Order" provides limited functional support, allowing applications to support both left-to-right (LTR) and right-to-left (RTL) arrangement formats when editing and displaying characters. Android
4.2 currently has full native-level support for the "right to left" text arrangement order, including providing a layout mirror tool, allowing developers to bring a high-quality user experience to every user, regardless of the user. Is the writing order from left to right or right to left.
Android 4.2 ensures that this new feature will not affect existing programs. If the previous program code is not modified, the appearance of the application will maintain the status quo. If you want to modify the program, with only minor changes, the application can be automatically "mirrored", making it easy to set the system language to a right-to-left writing format (Arabic, Hebrew Both English and Persian use this format). For example, the following screenshot shows the effect of the above settings:
Left to right layout
Right to left layout Method
To implement RTL (right to left) layout mirror reflection, just follow the following steps:
1. In your application In the declaration file (manifest), it is declared to enable RTL mirroring support. The specific method is: in the element of the manifest.xml declaration file, add android:supportsRtl="true"
2. Modify all the "left/right" layout attributes in the application and change them to Corresponding "start/end" layout
1) If your application is for the Android 4.2 target platform (the application's targetSdkVersion or minSdkVersion is 17 or higher), then you should replace the original "left" and "right" with "start" and "end" ". For example, android:paddingLeft should be replaced by android:paddingStart.
2) If you want your application to remain compatible with versions before Android 4.2 (that is, with targetSdkVersion or minSdkVersion of 16 or earlier), then you should add both "start" and "end", plus "left" and "right". For example, you should write: adnroid:paddingLeft and android:paddingStart at the same time.
In order to more accurately control the order in which applications write text on the UI (from left to right, or from right to left), Android 4.2 introduced the following API:
android:layoutDirection — This attribute sets the layout direction of the component
android:textDirection —
This attribute sets the text alignment direction of the component
android:textAlignment —
This property sets the alignment of text
getLayoutDirectionFromLocale() —This method is used to get the customary layout of the specified region
When using the right-to-left arrangement, you can even create custom layout methods, drawable objects, and other resources. By simply identifying your resources using the resource matcher "ldrtl", you can define resources as "right-to-left resources". In terms of debugging and optimizing right-to-left layout, HierarchyViewer currently supports hierarchical display of all information such as start/end attributes, layout direction, text direction, text alignment, etc.
So now is the time to develop beautiful Android apps for all users, regardless of whether their text language habits are left to right or right to left. We’re really looking forward to seeing these beautiful applications come to life!
When you see this picture, you can first think about how you would achieve this effect if it were you. Immediately thought of using RelativeLayout? NO,NO,NO,,,
2. Implementation code
xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:clipChildren="false" android:orientation="vertical">
="1.0"## android:scaleType ="fitCenter" android:src="@drawable/ic_launcher" /> LinearLayout> ##LinearLayout > ##Code Description: ##1. Just set android:clipChildren to false on the root node. The default is true
2. You can control how the excess part is displayed through android:layout_gravity.
3. The meaning of android:clipChildren:
Whether to limit the child View within its scope
Go through the document and find the following introduction
android:clipChildrensetClipChildren(boolean) Defines whether a child is limited to draw inside of its bounds or not. android:clipToPaddingsetClipToPadding(boolean)Defines whether the ViewGroup will clip its drawing surface so as to exclude the padding area.
The above is the detailed content of Complete explanation of Android Layout layout attributes. For more information, please follow other related articles on the PHP Chinese website!
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn