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):