"Turn" Pro Android Learning Note (27): User interface and Control (framelayout):

Source: Internet
Author: User

Framelayout

Framelayout typically contains only one control. If we set more than one control in Framelayout, the second control is stacked on top of the first control, and so on, one layer at a to the other. In the following example, we set two controls in the Framelayout, one visual, the other is not viewable nor occupies the position (GONE), click, by setting the visual properties, realize click to toggle the visual effect of the picture.

<?xml version= "1.0" encoding= "Utf-8"?>
<FramelayoutXmlns:android= "Http://schemas.android.com/apk/res/android"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent" >
<imageview android:id= "@+id/imageviewone"
android:src= "@drawable/sunflower01"
Android:scaletype= "Fitcenter"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"/>

<imageview android:id= "@+id/imageviewtwo"
android:src= "@drawable/sky02"
Android:scaletype= "Fitcenter"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:visibility= "Gone"/>
</FrameLayout>

The Java code is as follows:

Private ImageView one = null;
Private ImageView-n = null;
@Override
protected void OnCreate (Bundle savedinstancestate) {
Setcontentview (R.layout.ui_frame);
one = (ImageView) Findviewbyid (R.id.imageviewone);
(ImageView) Findviewbyid (r.id.imageviewtwo);
One.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
Two.setvisibility (view.visible);
One.setvisibility (view.gone);

}
});

Two.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
One.setvisibility (view.visible);
Two.setvisibility (view.gone);

}
});
}

Framelayout is typically used for a single control, but with its effect of stacking the controls, you can set some special, such as the following XML file:

<?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/imageviewone"
android:src= "@drawable/sunflower01"
android:scaletype= "Fitcenter"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"/>

<imageview android:id= "@+id/imageviewtwo"
android:src= "@drawable/png13"
android:scaletype= "center"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"/>
</FrameLayout>

RELATED Links: My Android development related articles

"Turn" Pro Android Learning Note (27): User interface and Control (framelayout):

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.