Android Studio 3.1.2 Layout files (1)

Source: Internet
Author: User

1. Newly introduced constraintlayout, the default layout of the new module after as 2.3 is constraintlayout if:

<?xml version="1.0"encoding="Utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"Xmlns:app="Http://schemas.android.com/apk/res-auto"Xmlns:tools="Http://schemas.android.com/tools"Android:layout_width="match_parent"Android:layout_height="match_parent"Tools:context="com.constraintlayout.app.Main2Activity"></android.support.constraint.ConstraintLayout>

In ConstraintLayout the layout scheme used, the support library needs to be build.gradle introduced:

  ' com.android.support.constraint:constraint-layout:1.1.0 '

In the traditional Android development, the interface is basically done by writing XML code, although Android studio also supports the visual way to write the interface, but it is not easy to operate, I also always do not recommend the use of visual methods to write the Android application interface.

And the constraintlayout is to solve this situation and appear. Contrary to the traditional way of writing interfaces, Constraintlayout is well suited to writing interfaces in a visual way, but is not a good way to write using XML. Of course, the XML code behind the visualization is still used, but the code is generated automatically by Android studio based on our operations.

In addition, Constraintlayout has an advantage, it can effectively solve the problem of too much nesting of layout. We usually write the interface, complex layout is always accompanied by multiple layers of nesting, and the more nested, the performance of the program is worse. Constraintlayout uses constraints to specify the positions and relationships of individual controls, which are somewhat similar to relativelayout, but are much more powerful than relativelayout.

Constraintdimensionratio

This property is to set the size of a view to a specific aspect ratio, such as setting a picture of the aspect ratio of 1:1,4:3, 16:9 and so on. By using Constraintlayout, you can simply use the Layout_constraintdimensionratio property.

<?xml version="1.0"encoding="Utf-8"? ><android.support.constraint.constraintlayout xmlns:android="http://schemas.android.com/apk/res/android"Xmlns:app="Http://schemas.android.com/apk/res-auto"Xmlns:tools="Http://schemas.android.com/tools"Android:layout_width="match_parent"Android:layout_height="match_parent"Android:id="@+id/constraintlayout"Tools:context="com.constraintlayout.app.MainActivity"> <ImageView Android:id="@+id/cat_image"Android:layout_width="0DP"Android:layout_height="wrap_content"App:layout_constraintleft_toleftof="Parent"App:layout_constrainttop_totopof="Parent"App:layout_constraintdimensionratio="4:3"App:layout_constraintright_torightof="Parent"App:layout_constrainthorizontal_bias="0"android:src="@mipmap/cat"/> <ImageView android:layout_width="0DP"Android:layout_height="wrap_content"android:src="@mipmap/ic_launcher"App:layout_constraintdimensionratio="4:3"App:layout_constraintbottom_tobottomof="Parent"App:layout_constraintleft_toleftof="Parent"App:layout_constrainttop_tobottomof="@+id/cat_image"App:layout_constraintvertical_bias="0.0"App:layout_constraintright_torightof="Parent"/></android.support.constraint.constraintlayout>

Android Studio 3.1.2 Layout files (1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.