Android UI layout: FrameLayout and androidframelayout

Source: Internet
Author: User

Android UI layout: FrameLayout and androidframelayout
A FrameLayout object is like a blank area on the screen, which can be filled with elements, such as an image. Note that all elements are placed in the leftmost area of the FrameLayout area. In addition, you cannot specify an exact location for these elements. If a FrameLayout contains multiple child elements, the display of the child elements will overlap with the previous one.

Instance: LayoutDemo
Running effect:


Code List:
Layout file: frame_layout.xml

<?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/photo"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:src="@drawable/bg"    /></FrameLayout>

Android: id defines the component id. In an application, we can use this id to access the defined element.
Android: layout_width = "match_parent" and android: layout_height = "match_parent" indicate that the FrameLayout layout can fill the space of the parent container in the X and Y directions.
Android: layout_width = "wrap_content" and android: layout_height + "wrap_content". The length and width of the imageviewelement can only be wrapped in bg.jpg without filling the parent container.

Java source code file: FrameLayoutActivity. java
package com.rainsong.layoutdemo;import android.app.Activity;import android.os.Bundle;public class FrameLayoutActivity extends Activity{    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState)    {        super.onCreate(savedInstanceState);        setContentView(R.layout.frame_layout);    }}


What is the nested framelayout in the layout file of android?

It is to nest another framelayout In the first framelayout. But it seems useless. Layout nesting implements Layout in a complex UI. For example, to implement a horizontal row of buttons in a vertical LinearLayout, a horizontal LinearLayout can be nested, add multiple buttons in horizontal LinearLayout. Because of the particularity of the FrameLayout layout, I feel it is useless to nest another FrameLayout. Unless nested FrameLayout is used to display some information separately, you can set its setVisibility (View. VISIBLE) display when you want to display it. If not, set its setVisibility (View. GONE) to not display it. I don't know what to say.

Android framelayout overlaps two la S. How can we make the lower layer not respond to events?

Blog.csdn.net/...372285
Android TouchEvent event Transfer Mechanism
When you receive the event, it means that the parent container does not intercept the event and the event is not consumed.
The parent container of your two la S is the same. When the event is passed to the parent sub-layout, it must also be passed to the sub-layout of the lower layer;
You don't want the following controls to handle this event
You can intercept the event in the parent container (in this way, all the child controls of the parent container cannot receive the touch event)
Or you don't need to set a listener for him.
You can either set it to gone or disable.
Either you re-write your sub-Control Touch event, do not process, directly return false

If the lower-layer layout is a View, it is recommended to set view. setEnabled (false) to true when a response is required!
If the lower-layer layout is a ViewGroup, you can re-write it to block the event so that it will not be passed. If you do not
SetEnabled (false) is used) if viewGroup cannot be set, you can call this method for all the sub-controls in it. It's easy to set clickable to flase and other attributes.
 

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.