{"id":186,"date":"2017-01-11T06:59:45","date_gmt":"2017-01-11T06:59:45","guid":{"rendered":"http:\/\/abhiandroid.com\/materialdesign\/?page_id=186"},"modified":"2019-06-13T10:30:08","modified_gmt":"2019-06-13T10:30:08","slug":"percentrelativelayout","status":"publish","type":"page","link":"https:\/\/abhiandroid.com\/materialdesign\/percentrelativelayout","title":{"rendered":"PercentRelativeLayout Tutorial With Example In Android Studio"},"content":{"rendered":"<p><span style=\"color: #008000;\"><strong>PercentRelativeLayout<\/strong>\u00a0<\/span>in Android is a subclass of RelativeLayout that supports percentage based margin and dimensions for Views(Button, TextView or any other view).<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-195\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-In-Android-Studio.jpg\" alt=\"percent-relative-layout-in-android-studio\" width=\"483\" height=\"354\" srcset=\"https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-In-Android-Studio.jpg 483w, https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-In-Android-Studio-300x220.jpg 300w\" sizes=\"auto, (max-width: 483px) 100vw, 483px\" \/><\/p>\n<p><strong><span style=\"color: #008000;\">Percent Support Library:<\/span> <\/strong>Percent Support Library provides a feature to set the dimensions and margins in the term of Percentage. It has two pre built Layouts- the PercentRelativeLayout and PercentFrameLayout. In this article we focused on PercentRelativeLayout. This library is pretty easy to use because it has same Relative Layout and FrameLayout that we are familiar with, just with some additional new functionalities.<\/p>\n<p><span style=\"color: #ff0000;\"><strong>Important Note &#8211;<\/strong>\u00a0\u00a0<\/span>To use percentrelativelayout you need to add Percent Support Library dependency in build.gradle file.<\/p>\n<p><span style=\"color: #008000;\"><strong>Gradle Scripts &gt; build.gradle (Module:App) -&gt; inside\u00a0dependencies<\/strong><\/span><\/p>\n<pre>compile 'com.android.support:percent:23.3.0' \/\/ Percent Support Library<\/pre>\n<h4><strong>PercentRelativeLayout Vs Relative Layout In Android:<\/strong><\/h4>\n<p>PercentRelativeLayout class extends from Relative Layout class so it supports all the features, attributes of RelativeLayout and it has percentage dimensions so it also supports some features of LinearLayout. <strong>In Simple words we can say that PercentRelativeLayout has features of both Layouts with reduced view complexity.<\/strong><\/p>\n<hr \/>\n<h4><strong>Need of PercentRelativeLayout In Android<\/strong><\/h4>\n<p>In Android there are lot of Layout&#8217;s that can be used at the time of development but at last we always end up with our main three layouts Linear Layout, Relative Layout and FrameLayout. In case if we need to create complex view then we use weight property of LinearLayout to distribute view across screens. But while using weight property we must have noticed that we have to add a default container view to encapsulate our child view . We can follow this approach but it adds an additional view hierarchy in our layout&#8217;s which is of no use except holding weight sum value and child view. After the introduction of PercentRelativeLayout we can put percentage dimension and margins to our view that helps us to remove the problem of existing RelativeLayout.<\/p>\n<hr \/>\n<h4><strong>Short Description About RelativeLayout:<\/strong><\/h4>\n<p>Relative Layout is very flexible layout used in android for custom layout designing. It gives us the flexibility to position our component&#8217;s based on the relative or sibling component\u2019s position. Just because it allows us to position the component anywhere we want so it is considered as most flexible layout. For the same reason Relative layout is the most used layout after the Linear Layout in Android. It allow its child view to position relative to each other or relative to the container or another container. You can read <a href=\"\/ui\/relative-layout\">full tutorial about relative layout<\/a>.<\/p>\n<p><span style=\"color: #ff0000;\"><strong>Important Note:\u00a0<\/strong><\/span>In PercentRelativeLayout, it is not necessary to specify layout_width and layout_height attributes if we specify layout_widthPercent attribute. If in case we want the view to be able to take up more space than what percentage value permits then we can add layout_width and layout_height attributes with wrap_content value. In that case if the size of content is larger than percentage size then it will be automatically resized using wrap_content rule. If we don&#8217;t use layout_height and layout_width attribute then android studio shows us an error marker on element in the editor but it will be automatically ignored at run-time.<\/p>\n<p><span style=\"color: #008000;\">Basic PercentRelativeLayout XML Code:<\/span><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentRelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"&gt;\r\n    &lt;!-- Add Child View's Here... --&gt;\r\n&lt;\/android.support.percent.PercentRelativeLayout&gt;\r\n<\/pre>\n<hr \/>\n<h4><strong>Attributes of PercentRelativeLayout<\/strong><\/h4>\n<p>Now let\u2019s we discuss some common attributes of a PercentRelativeLayout that helps us to configure it in our layout (xml). It supports all the attributes of RelativeLayout but here we are only discuss some additional attributes.<\/p>\n<p><span style=\"color: #ff0000;\"><strong>Very Important Note:<\/strong><\/span>\u00a0Before you use below code make sure you have added Percent Support Library dependency in build.gradle file in depencies.<\/p>\n<p><span style=\"color: #008000;\"><strong>Gradle Scripts &gt; build.gradle (Module:App) -&gt; inside\u00a0dependencies<\/strong><\/span><\/p>\n<pre>compile 'com.android.support:percent:23.3.0' \/\/ Percent Support Library<\/pre>\n<ul>\n<li><strong><span style=\"color: #008000;\">layout_widthPercent:<\/span><\/strong> This attribute is used to set the width of the view in percentage. Below we set 50% value for the widthPercent and wrap_content value for the height of the TextView.\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentRelativeLayout\r\n    xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"&gt;\r\n    &lt;TextView\r\n        app:layout_widthPercent=\"50%\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:textColor=\"#000\"\r\n        android:textSize=\"20sp\"\r\n        android:text=\"AbhiAndroid\" \/&gt;\r\n&lt;\/android.support.percent.PercentRelativeLayout&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-197\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-Width-Percent-In-Android-Studio.jpg\" alt=\"percent-relative-layout-width-percent-in-android-studio\" width=\"206\" height=\"164\" \/><\/li>\n<li><span style=\"color: #008000;\"><strong>layout_heightPercent:<\/strong><\/span> This attribute is used to set the height of the view in percentage. Below we set 30% value for the heightPercent and wrap_content value for the width of the TextView.\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentRelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"&gt;\r\n    &lt;TextView\r\n        android:layout_width=\"wrap_content\"\r\n        android:text=\"AbhiAndroid\"\r\n        android:textColor=\"#000\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_heightPercent=\"30%\" \/&gt;\r\n&lt;\/android.support.percent.PercentRelativeLayout&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-198\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-Height-Percent-In-Android-Studio.jpg\" alt=\"percent-relative-layout-height-percent-in-android-studio\" width=\"189\" height=\"166\" \/><\/li>\n<li><strong><span style=\"color: #008000;\">layout_marginPercent:<\/span> <\/strong>This attribute is used to set the margin for view in term of percentage. This attribute set the same margin from all the sides. Below we set wrap_content vlaue for height and width and 10% margin from all the sides of TextView.\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentRelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"&gt;\r\n    &lt;TextView\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"AbhiAndroid\"\r\n        android:textColor=\"#000\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_marginPercent=\"10%\" \/&gt;\r\n&lt;\/android.support.percent.PercentRelativeLayout&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-200\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-Margin-Percent-In-Android-Studio.jpg\" alt=\"percent-relative-layout-margin-percent-in-android-studio\" width=\"203\" height=\"131\" \/><\/li>\n<li><span style=\"color: #008000;\"><strong>layout_marginLeftPercent:<\/strong><\/span> This attribute is used to set the percentage margin to the left side of the view. Below we set wrap_content value for height and width and 10% margin to the left side of the TextView.\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentRelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"&gt;\r\n    &lt;TextView\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"AbhiAndroid\"\r\n        android:textColor=\"#000\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_marginLeftPercent=\"10%\" \/&gt;\r\n&lt;\/android.support.percent.PercentRelativeLayout&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-201\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-MarginLeft-Percent-In-Android-Studio.jpg\" alt=\"percent-relative-layout-marginleft-percent-in-android-studio\" width=\"191\" height=\"136\" \/><\/li>\n<li><span style=\"color: #008000;\"><strong>layout_marginTopPercent:<\/strong><\/span> This attribute is used to set the percentage margin to the top side of the view.Below we set wrap_content value for height and width and 10% margin to the top side of the TextView.\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentRelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"&gt;\r\n    &lt;TextView\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"AbhiAndroid\"\r\n        android:textColor=\"#000\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_marginTopPercent=\"10%\" \/&gt;\r\n&lt;\/android.support.percent.PercentRelativeLayout&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-202\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-MarginTop-Percent-In-Android-Studio.jpg\" alt=\"percent-relative-layout-margintop-percent-in-android-studio\" width=\"204\" height=\"150\" \/><\/li>\n<li><span style=\"color: #008000;\"><strong>layout_marginRightPercent:<\/strong><\/span> This attribute is used to set the percentage margin to the right side of the view. Below we set wrap_content value for height and width and 10% margin to the right side of the TextView. In this example we set right alignment of TextView so that we can easily check the use of this attribute.\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentRelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"&gt;\r\n    &lt;TextView\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"AbhiAndroid\"\r\n        android:textColor=\"#000\"\r\n        android:textSize=\"20sp\"\r\n        android:layout_alignParentRight=\"true\"\r\n        app:layout_marginRightPercent=\"10%\" \/&gt;\r\n&lt;\/android.support.percent.PercentRelativeLayout&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-203\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-Margin-Right-Percent-In-Android-Studio.jpg\" alt=\"percent-relative-layout-margin-right-percent-in-android-studio\" width=\"196\" height=\"162\" \/><\/li>\n<li><span style=\"color: #008000;\"><strong>layout_marginBottomPercent:<\/strong><\/span> This attribute is used to set the percentage margin from bottom side of the view. Below we set wrap_content value for height and width and 10% margin from the bottom side of the TextView. In this example we set bottom alignment of TextView so that we can easily check the use of this attribute.\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentRelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"&gt;\r\n    &lt;TextView\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:text=\"AbhiAndroid\"\r\n        android:textColor=\"#000\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_marginBottomPercent=\"10%\" \/&gt;\r\n&lt;\/android.support.percent.PercentRelativeLayout&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-204\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-MarginBottom-Percent-In-Android-Studio.jpg\" alt=\"percent-relative-layout-marginbottom-percent-in-android-studio\" width=\"195\" height=\"308\" srcset=\"https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-MarginBottom-Percent-In-Android-Studio.jpg 195w, https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-MarginBottom-Percent-In-Android-Studio-190x300.jpg 190w\" sizes=\"auto, (max-width: 195px) 100vw, 195px\" \/><\/li>\n<\/ul>\n<hr \/>\n<h4><strong>PercentRelativeLayout Example In Android Studio:<\/strong><\/h4>\n<p>Below is the example of PercentRelativeLayout in which we create a Login Form with 2 fields user name and Password. In this example we take 2 EditText, 2 TextView and 1 Login Button. For these views we set the dimensions and margin in form of percentage. If a user click on the login Button then a \u201cThank You\u201d message with user name is displayed on the screen with the help of Toast.<\/p>\n<p style=\"text-align: center;\"><a class=\"download\" href=\"https:\/\/github.com\/abhisheksaini4\/PercentRelativeLayoutExample\" target=\"_blank\" rel=\"nofollow\">Download Code<\/a><a class=\"help\" title=\"Learn How To Download Code And Import In Android Studio\" href=\"\/androidstudio\/download-code-abhiandroid\" target=\"_blank\" rel=\"nofollow\"> ?<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-209\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-Example-In-Android-Studio.jpg\" alt=\"percent-relative-layout-example-in-android-studio\" width=\"285\" height=\"377\" srcset=\"https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-Example-In-Android-Studio.jpg 285w, https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/01\/Percent-Relative-Layout-Example-In-Android-Studio-227x300.jpg 227w\" sizes=\"auto, (max-width: 285px) 100vw, 285px\" \/><br \/>\n<span style=\"color: #008000;\"><strong>Step 1:<\/strong> <\/span>Create A New Project And Name It PercentRelativeLayoutExample.<\/p>\n<p><span style=\"color: #008000;\"><strong>Step 2:<\/strong> <\/span>Open Gradle Scripts &gt; build.gradle and add Percent Support Library dependency.<\/p>\n<pre>apply plugin: 'com.android.application'\r\nandroid {\r\ncompileSdkVersion 24\r\nbuildToolsVersion \"24.0.1\"\r\ndefaultConfig {\r\napplicationId \"abhiandroid.percentrelativelayoutexample\"\r\nminSdkVersion 16\r\ntargetSdkVersion 24\r\nversionCode 1\r\nversionName \"1.0\"\r\n}\r\nbuildTypes {\r\nrelease {\r\nminifyEnabled false\r\nproguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'\r\n}\r\n}\r\n}\r\ndependencies {\r\ncompile fileTree(dir: 'libs', include: ['*.jar'])\r\ntestCompile 'junit:junit:4.12'\r\ncompile 'com.android.support:appcompat-v7:24.1.1'\r\ncompile 'com.android.support:percent:23.3.0' \/\/ Percent Support Library\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Step 3:<\/strong><\/span> Open res -&gt; layout -&gt; activity_main.xml (or) main.xml and add following code:<br \/>\nIn this Step we take 2 EditText&#8217;s, 2 TextView&#8217;s and 1 Login Button and for these views we set the dimensions and margin in form of percentage. Note that in all the view&#8217;s i didn&#8217;t take layout_widht attribute and it still works fine. Android Studio shows a error line on element but it will be automatically ignored at runtime.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentRelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"&gt;\r\n    &lt;!--\r\n    TextView's for labels and EditText for getting value from user\r\n    --&gt;\r\n    &lt;TextView\r\n        android:id=\"@+id\/txtUserName\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"UserName :\"\r\n        android:textColor=\"#000\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_marginLeftPercent=\"10%\"\r\n        app:layout_marginTopPercent=\"10%\"\r\n        app:layout_widthPercent=\"30%\" \/&gt;\r\n    &lt;TextView\r\n        android:id=\"@+id\/txtPassword\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_below=\"@+id\/txtUserName\"\r\n        android:text=\"Password :\"\r\n        android:textColor=\"#000\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_marginLeftPercent=\"10%\"\r\n        app:layout_marginTopPercent=\"4%\"\r\n        app:layout_widthPercent=\"30%\" \/&gt;\r\n    &lt;EditText\r\n        android:id=\"@+id\/userName\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_toRightOf=\"@+id\/txtUserName\"\r\n        android:hint=\"User Name\"\r\n        android:textColor=\"#000\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_marginLeftPercent=\"3%\"\r\n        app:layout_marginTopPercent=\"8%\"\r\n        app:layout_widthPercent=\"50%\" \/&gt;\r\n    &lt;EditText\r\n        android:id=\"@+id\/password\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_toRightOf=\"@+id\/txtPassword\"\r\n        android:hint=\"Password\"\r\n        android:inputType=\"textPassword\"\r\n        android:textColor=\"#000\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_marginLeftPercent=\"3%\"\r\n        app:layout_marginTopPercent=\"16%\"\r\n        app:layout_widthPercent=\"50%\" \/&gt;\r\n    &lt;!-- Login Button --&gt;\r\n    &lt;Button\r\n        android:id=\"@+id\/login\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_below=\"@+id\/password\"\r\n        android:layout_centerHorizontal=\"true\"\r\n        android:background=\"#F0F\"\r\n        android:text=\"Login\"\r\n        android:textColor=\"#fff\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_marginPercent=\"5%\"\r\n        app:layout_widthPercent=\"60%\" \/&gt;\r\n&lt;\/android.support.percent.PercentRelativeLayout&gt;\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Step 4 :<\/strong><\/span> Open src -&gt; package -&gt; MainActivity.java<\/p>\n<p>In this step we open the MainActivity and add the code for initiates the views(EditText and Button). After that we implement setOnClickListener event on login Button so that whenever a user click on Button a thank you message if a user already fill both fields or a error message that enter your user name and password is displayed on the screen with the help of Toast.<\/p>\n<pre>package abhiandroid.percentrelativelayoutexample;\r\nimport android.os.Bundle;\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.view.View;\r\nimport android.widget.Button;\r\nimport android.widget.EditText;\r\nimport android.widget.Toast;\r\npublic class MainActivity extends AppCompatActivity {\r\nButton login;\r\nEditText userName, password;\r\n@Override\r\nprotected void onCreate(Bundle savedInstanceState) {\r\nsuper.onCreate(savedInstanceState);\r\nsetContentView(R.layout.activity_main);\r\n\/\/ init the View's\r\nuserName = (EditText) findViewById(R.id.userName);\r\npassword = (EditText) findViewById(R.id.password);\r\nlogin = (Button) findViewById(R.id.login);\r\n\/\/ perform setOnClickListener Event on Login Button\r\nlogin.setOnClickListener(new View.OnClickListener() {\r\n@Override\r\npublic void onClick(View view) {\r\n\/\/ validate user name and password\r\nif (userName.getText().toString().trim().length() &gt; 0 &amp;&amp; password.getText().toString().trim().length() &gt; 0) {\r\n\/\/ display a thanks you message with user name\r\nToast.makeText(getApplicationContext(), \"Thank You \" + userName.getText().toString(), Toast.LENGTH_SHORT).show();\r\n} else {\r\n\/\/ display an error message that fill user name and password\r\nToast.makeText(getApplicationContext(), \"Please Enter Your User Name And Password.!!\", Toast.LENGTH_SHORT).show();\r\n}\r\n}\r\n});\r\n}\r\n}\r\n<\/pre>\n<p><span style=\"color: #008000;\"><strong>Output:<\/strong><\/span><\/p>\n<p>Now run the App and you will login form designed using PercentRelativeLayout.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PercentRelativeLayout\u00a0in Android is a subclass of RelativeLayout that supports percentage based margin and dimensions for Views(Button, TextView or any other view). Percent Support Library: Percent Support Library provides a feature to set the dimensions and margins in the term of Percentage. It has two pre built Layouts- the PercentRelativeLayout and PercentFrameLayout. In this article we &hellip; <a href=\"https:\/\/abhiandroid.com\/materialdesign\/percentrelativelayout\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">PercentRelativeLayout Tutorial With Example In Android Studio<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"home.php","meta":{"footnotes":""},"class_list":["post-186","page","type-page","status-publish","hentry"],"psp_head":"<title>PercentRelativeLayout Tutorial With Example In Android Studio \u2013 Android Material Design Tutorial<\/title>\r\n<meta name=\"description\" content=\"Read Percent Relative Layout material design tutorial with example in Android Studio. PercentRelativeLayout in Android is a subclass of RelativeLayout that supports percentage based margin and dimensions for Views(Button, TextView or any other view).\" \/>\r\n<meta name=\"robots\" content=\"index,follow\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/abhiandroid.com\/materialdesign\/percentrelativelayout\" \/>\r\n","_links":{"self":[{"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/pages\/186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/comments?post=186"}],"version-history":[{"count":3,"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/pages\/186\/revisions"}],"predecessor-version":[{"id":739,"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/pages\/186\/revisions\/739"}],"wp:attachment":[{"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/media?parent=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}