Learning android from scratch (FrameLayout frame layout. 14th .)

Source: Internet
Author: User

Learning android from scratch (FrameLayout frame layout. 14th .)

FrameLayout layout (frame layout) is to open up an area on the screen to fill all the components, but with FrameLayout layout, all the components are placed in the upper left corner of the screen, in addition, all components can be stacked for display.

 <frameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent" >      
         
   </frameLayout>





.................................................................. Beautiful cut line ..................................................................
Configure the project directly in the JAVA file without the xml 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 the width and height of FrameLayout for the layout. layoutParams = new FrameLayout. layoutParams (ViewGroup. layoutParams. FILL_PARENT, ViewGroup. layoutParams. FILL_PARENT); // set the height and width of the image FrameLayout. layoutParams imageLayoutParams = new FrameLayout. layoutParams (ViewGroup. layoutParams. MATCH_PARENT, 311); // set the width and height for the button FrameLayout. layoutParams buttonLayoutParams = new FrameLayout. layoutParams (281,173); // set the width and height of the text to FrameLayout. layoutParams textLayoutParams = new FrameLayout. layoutParams (183, 85); ImageView imageView = new ImageView (this); // create an ImageView object imageView. setImageResource (R. drawable. kill); // set the image information layout. addView (imageView, imageLayoutParams); // Add the imageView to the Framelayout layout. Button button = new Button (this); // create the Button object button. setText ("button"); // set the title 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 JAVA file configuration and xml file configuration are the same. You can set the XML layout and Dynamic Layout as needed.
Next prediction: 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.