Learn android<framelayout frame layout from scratch. 14 .>

Source: Internet
Author: User

Framelayout layout (frame layout) is the creation of an area on the screen to fill all the components, but using the Framelayout layout puts all the components in the upper-left corner of the screen, and all the components can be stacked for display.
<?xml version= "1.0" encoding= "Utf-8"? ><framelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "    android:layout_width=" match_parent "    android:layout_height=" match_parent ">      < ImageView          android:id= "@+id/imageview1"          android:layout_width= "match_parent"          android:layout_height= " 322DP "          android:src=" @drawable/kill "/>    <button        android:id=" @+id/button1 "        android:layout_ Width= "240DP"        android:layout_height= "107DP"        android:text= "button"/>    <textview        Android:id= "@+id/textview1"        android:layout_width= "154DP"        android:layout_height= "62DP"        android: text= "Large Text"        android:textappearance= "? Android:attr/textappearancelarge"/>  </framelayout >

..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ... .. ....... There is no beauty in the dividing line ... ..... ..... ..... ..... ..... .......-.....-......................
do not need an XML file to configure the project directly in the Java file
Package Com.example.framelayout;import Android.os.bundle;import Android.app.activity;import android.view.ViewGroup ; Import Android.widget.button;import Android.widget.framelayout;import Android.widget.imageview;import Android.widget.textview;public class Mainactivity extends Activity {@Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Framelayout layout = new Framelayout (this),//set width and height for layout framelayout.layoutparams layoutparams = new Framelayout.layoutparams (viewgroup.layoutparams.fill_parent,viewgroup.layoutparams.fill_parent);// Set the height and width of the picture framelayout.layoutparams imagelayoutparams = new Framelayout.layoutparams (ViewGroup.LayoutParams.MATCH_ PARENT, 311);//set width and height for buttons framelayout.layoutparams buttonlayoutparams = new Framelayout.layoutparams (281, 173);// Set the width and height of the text framelayout.layoutparams textlayoutparams = new Framelayout.layoutparams (183); ImageView ImageView = new ImageView (this);//Create ImageView Object Imageview.setimageresource (R.drawable.kill);/Set Picture information Layout.addview (ImageView, imagelayoutparams);//Add ImageView to framelayout layout button button = New button (this) ;//Create button Object Button.settext ("button");//Set Caption Layout.addview (button, buttonlayoutparams);// Add the button to the Framelayout layout TextView textview=new TextView (this);//Create TextView Object Textview.settext ("TextView");// Set the title Layout.addview (TextView, textlayoutparams);//Add TextView to Framelayout super.addcontentview (layout, Layoutparams);//Add Framelayout to content}}

You can see that the effects of using the Java file configuration and the XML file configuration are the same, the way the XML layout and the dynamic layout can be set according to your own needs
forecast for next section: Table layout tablelayout
Related Article

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.