{"id":252,"date":"2017-01-21T05:53:28","date_gmt":"2017-01-21T05:53:28","guid":{"rendered":"http:\/\/abhiandroid.com\/materialdesign\/?page_id=252"},"modified":"2019-06-13T10:03:39","modified_gmt":"2019-06-13T10:03:39","slug":"percentframelayout","status":"publish","type":"page","link":"https:\/\/abhiandroid.com\/materialdesign\/percentframelayout","title":{"rendered":"PercentFrameLayout Tutorial With Example In Android Studio"},"content":{"rendered":"<p>In Android PercentFrameLayout is a subclass of FrameLayout that supports percentage based margin and dimensions for Views(Button, TextView or any other view).<\/p>\n<p>PercentFrameLayout class extends from FrameLayout class so it supports all the features, attributes of FrameLayout and it has percentage dimensions so it also supports some features of Linear Layout. In Simple words we can say that PercentFrameLayout has features of both Layouts with reduced view complexity.<\/p>\n<p><span style=\"color: #008000;\"><strong>Percent Support Library:<\/strong><\/span> Percent Support Library provides feature to set the dimensions and margins in the term of Percentage. It has two pre built Layouts- the PercentFrameLayout and <a href=\"\/materialdesign\/percentrelativelayout\">PercentRelativeLayout<\/a>. This library is pretty easy to use because it has same Relative Layout and Frame Layout that we are familiar with, just with some additional new features. In this article we only discuss\u00a0PercentFrameLayout.<\/p>\n<p><strong>Important Note \u2013<\/strong>\u00a0\u00a0To use PercentFrameLayout first include\u00a0Percent Support Library dependency file in build.grade(Module: app).<\/p>\n<p><strong><span style=\"color: #008000;\">Gradle Scripts &gt; build.gradle (Module:App) -&gt; inside dependencies<\/span><\/strong><\/p>\n<pre>dependencies {\r\ncompile 'com.android.support:percent:23.3.0'\r\n}\r\n<\/pre>\n<h4><strong>Need of PercentFrameLayout:<\/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 ends up with our main three layouts LinearLayout, RelativeLayout and FrameLayout. In many situations\u00a0when\u00a0we 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 PercentFrameLayout we can put percentage dimension and margins to our view that helps us to remove the problem of existing FrameLayout.<\/p>\n<p><span style=\"color: #008000;\"><strong>Short Description About FrameLayout In Android:<\/strong><\/span><\/p>\n<p>In Android Frame Layout is one of the simplest layout used to organize view controls. It is designed to block an area on the screen. Frame Layout should be used to hold child view, because it can be difficult to display single views at a specific area on the screen without overlapping each other. You can read full <a href=\"\/ui\/framelayout\">FrameLayout tutorial here<\/a>.<\/p>\n<p><span style=\"color: #ff0000;\"><b>Important<\/b><\/span><strong style=\"color: #ff0000;\">\u00a0Note:<\/strong><\/p>\n<p>In PercentFrameLayout, 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 runtime.<\/p>\n<p><span style=\"color: #008000;\"><strong>Basic PercentFrameLayout XML Code:<\/strong><\/span><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentFrameLayout 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.PercentFrameLayout&gt;\r\n<\/pre>\n<hr \/>\n<h4><strong>Attributes of PercentFrameLayout:<\/strong><\/h4>\n<p>Now let\u2019s we discuss some common attributes of a PercentFrameLayout that helps us to configure it in our layout (xml). It supports all the attributes of FrameLayout but here we are only discuss some additional attributes.<\/p>\n<p><span style=\"color: #ff0000;\"><strong>Important Note &#8211;<\/strong><\/span> Before using below code please include Percent Support Library dependency file in build.grade(Module: app).<\/p>\n<p><strong><span style=\"color: #008000;\">Gradle Scripts &gt; build.gradle (Module:App) -&gt; inside dependencies<\/span><\/strong><\/p>\n<pre>dependencies {\r\ncompile 'com.android.support:percent:23.3.0'\r\n}<\/pre>\n<p><span style=\"color: #008000;\"><strong>1. layout_widthPercent:<\/strong><\/span> This attribute is used to set the width of the view in percentage.<\/p>\n<p>Below we set 50% value for the widthPercent and wrap_content value for the height of the TextView.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentFrameLayout\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.PercentFrameLayout&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-273\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrameLayout-Width-Percent-In-Android-Studio.png\" alt=\"PercentFrameLayout Width Percent In Android Studio\" width=\"225\" height=\"247\" \/><br \/>\n<span style=\"color: #008000;\"><strong>2. layout_heightPercent:<\/strong> <\/span>This attribute is used to set the height of the view in percentage.<br \/>\nBelow we set 20% value for the heightPercent and wrap_content value for the width of the TextView.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentFrameLayout 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=\"20%\" \/&gt;\r\n&lt;\/android.support.percent.PercentFrameLayout&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-276\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrameLayout-HeightPercent-In-Android-Studio.png\" alt=\"PercentFrameLayout HeightPercent In Android Studio\" width=\"226\" height=\"226\" srcset=\"https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrameLayout-HeightPercent-In-Android-Studio.png 226w, https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrameLayout-HeightPercent-In-Android-Studio-150x150.png 150w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/><\/p>\n<p><span style=\"color: #008000;\"><strong>3. layout_marginPercent:<\/strong><\/span> This attribute is used to set the margin for view in term of percentage. This attribute set the same margin from all the sides.<br \/>\nBelow we set wrap_content vlaue for height and width and 20% margin from all the sides of TextView.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentFrameLayout 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=\"20%\" \/&gt;\r\n&lt;\/android.support.percent.PercentFrameLayout&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-277\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrameLayout-Margin-Percent-In-Android-Studio.png\" alt=\"PercentFrameLayout Margin Percent In Android Studio\" width=\"227\" height=\"258\" \/><br \/>\n<span style=\"color: #008000;\"><strong>4. layout_marginLeftPercent:<\/strong> <\/span>This attribute is used to set the percentage margin to the left side of the view.<\/p>\n<p>Below we set wrap_content value for height and width and 15% margin to the left side of the TextView.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentFrameLayout 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=\"15%\" \/&gt;\r\n&lt;\/android.support.percent.PercentFrameLayout&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-278\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrameLayout-MarginLeft-Percent-In-Android-Studio.png\" alt=\"PercentFrameLayout MarginLeft Percent In Android Studio\" width=\"226\" height=\"225\" srcset=\"https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrameLayout-MarginLeft-Percent-In-Android-Studio.png 226w, https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrameLayout-MarginLeft-Percent-In-Android-Studio-150x150.png 150w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/><br \/>\n<span style=\"color: #008000;\"><strong>5. layout_marginTopPercent:<\/strong><\/span> This attribute is used to set the percentage margin to the top side of the view.<\/p>\n<p>Below we set wrap_content value for height and width and 15% margin to the top side of the TextView.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentFrameLayout 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=\"15%\" \/&gt;\r\n&lt;\/android.support.percent.PercentFrameLayout&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-279\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrameLayout-MarginTop-Percent-In-Android-Studio.png\" alt=\"PercentFrameLayout MarginTop Percent In Android Studio\" width=\"231\" height=\"256\" \/><br \/>\n<span style=\"color: #008000;\"><strong>6. layout_marginRightPercent:<\/strong><\/span> This attribute is used to set the percentage margin to the right side of the view.<\/p>\n<p>Below we set wrap_content value for height and width and 15% margin to the right side of the TextView. In this example we set right gravity of TextView so that we can easily check the use of this attribute.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentFrameLayout 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_gravity=\"right\"\r\n        android:text=\"AbhiAndroid\"\r\n        android:textColor=\"#000\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_marginRightPercent=\"15%\" \/&gt;\r\n&lt;\/android.support.percent.PercentFrameLayout&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-280\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrameLayout-MarginRight-Percent-In-Android-Studio.png\" alt=\"PercentFrameLayout MarginRight Percent In Android Studio\" width=\"226\" height=\"245\" \/><br \/>\n<span style=\"color: #008000;\"><strong>7. layout_marginBottomPercent:<\/strong><\/span> This attribute is used to set the percentage margin from bottom side of the view.<\/p>\n<p>Below we set wrap_content value for height and width and 15% margin from the bottom side of the TextView. In this example we set bottom gravity of TextView so that we can easily check the use of this attribute.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.percent.PercentFrameLayout 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_gravity=\"bottom\"\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.PercentFrameLayout&gt;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-281\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrameLayout-MarginBottom-Percent-In-Android-Studio.png\" alt=\"PercentFrameLayout MarginBottom Percent In Android Studio\" width=\"226\" height=\"327\" srcset=\"https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrameLayout-MarginBottom-Percent-In-Android-Studio.png 226w, https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrameLayout-MarginBottom-Percent-In-Android-Studio-207x300.png 207w\" sizes=\"auto, (max-width: 226px) 100vw, 226px\" \/><\/p>\n<hr \/>\n<h4><strong>PercentFrameLayout Example In Android Studio:<\/strong><\/h4>\n<p>Below is the example of PercentFrameLayout in which we create a Registration Form with 3 fields User Name, Phone No and Password. In this example we take 3 EditText and 1 Register Button.\u00a0And for these views we set the dimensions and margin in form of percentage. If a user click on the Register 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\/PercentFrameLayout\" 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><span style=\"color: #008000;\"><strong><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-271\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrame-Layout-Example-In-Android-Studio.png\" alt=\"PercentFrame Layout Example In Android Studio\" width=\"314\" height=\"435\" srcset=\"https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrame-Layout-Example-In-Android-Studio.png 314w, https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/01\/PercentFrame-Layout-Example-In-Android-Studio-217x300.png 217w\" sizes=\"auto, (max-width: 314px) 100vw, 314px\" \/>Step 1:<\/strong><\/span> Create A New Project And Name It PercentFrameLayout<\/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.percentframelayout\"\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 3 EditText&#8217;s and 1 Register 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_width 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.PercentFrameLayout 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\"\r\n    android:background=\"@drawable\/background\"&gt;\r\n&lt;!--\r\n    3 EditText's for user Name, Phone No and Password\r\n--&gt;\r\n    &lt;EditText\r\n        android:id=\"@+id\/userName\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_gravity=\"center_horizontal\"\r\n        android:hint=\"User Name\"\r\n        android:imeOptions=\"actionNext\"\r\n        android:singleLine=\"true\"\r\n        android:textColor=\"#fff\"\r\n        android:textColorHint=\"#fff\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_marginTopPercent=\"15%\"\r\n        app:layout_widthPercent=\"80%\" \/&gt;\r\n    &lt;EditText\r\n        android:id=\"@+id\/phoneNo\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_gravity=\"center_horizontal\"\r\n        android:hint=\"Phone No\"\r\n        android:imeOptions=\"actionNext\"\r\n        android:inputType=\"number\"\r\n        android:singleLine=\"true\"\r\n        android:textColor=\"#fff\"\r\n        android:textColorHint=\"#fff\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_marginTopPercent=\"25%\"\r\n        app:layout_widthPercent=\"80%\" \/&gt;\r\n    &lt;EditText\r\n        android:id=\"@+id\/password\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_gravity=\"center_horizontal\"\r\n        android:hint=\"Password\"\r\n        android:imeOptions=\"actionDone\"\r\n        android:singleLine=\"true\"\r\n        android:textColor=\"#fff\"\r\n        android:textColorHint=\"#fff\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_marginTopPercent=\"34%\"\r\n        app:layout_widthPercent=\"80%\" \/&gt;\r\n    &lt;Button\r\n        android:id=\"@+id\/register\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_gravity=\"center\"\r\n        android:background=\"@color\/colorPrimary\"\r\n        android:text=\"Register\"\r\n        android:textColor=\"#fff\"\r\n        android:textSize=\"20sp\"\r\n        app:layout_widthPercent=\"80%\" \/&gt;\r\n&lt;\/android.support.percent.PercentFrameLayout&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 Register Button so that whenever a user click on Button a thank you message appear if a user fill all the fields or an error message appear if fields are empty telling user\u00a0&#8216;Please Fill All The Fields&#8217; is displayed on the screen by using a Toast.<\/p>\n<pre>package abhiandroid.percentframelayout;\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 register;\r\nEditText userName, phoneNo, 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\nphoneNo = (EditText) findViewById(R.id.phoneNo);\r\npassword = (EditText) findViewById(R.id.password);\r\nregister = (Button) findViewById(R.id.register);\r\n\/\/ perform setOnClickListener Event on Register Button\r\nregister.setOnClickListener(new View.OnClickListener() {\r\n@Override\r\npublic void onClick(View view) {\r\nif (userName.getText().toString().trim().length() &gt; 0 &amp;&amp; phoneNo.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 Fill All The Fields.!!\", Toast.LENGTH_SHORT).show();\r\n}\r\n}\r\n});\r\n}\r\n}\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>Now run the App and you will see login form which is designed using PercentFrameLayout.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Android PercentFrameLayout is a subclass of FrameLayout that supports percentage based margin and dimensions for Views(Button, TextView or any other view). PercentFrameLayout class extends from FrameLayout class so it supports all the features, attributes of FrameLayout and it has percentage dimensions so it also supports some features of Linear Layout. In Simple words we &hellip; <a href=\"https:\/\/abhiandroid.com\/materialdesign\/percentframelayout\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">PercentFrameLayout 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-252","page","type-page","status-publish","hentry"],"psp_head":"<title>PercentFrameLayout Tutorial With Example In Android Studio \u2013 Android Material Design Tutorial<\/title>\r\n<meta name=\"description\" content=\"Complete Tutorial on PercentFrameLayout to show view based on percentage margin with example &amp; source code in Android Studio. In Android PercentFrameLayout is a subclass of FrameLayout 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\/percentframelayout\" \/>\r\n","_links":{"self":[{"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/pages\/252","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=252"}],"version-history":[{"count":3,"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/pages\/252\/revisions"}],"predecessor-version":[{"id":695,"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/pages\/252\/revisions\/695"}],"wp:attachment":[{"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/media?parent=252"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}