Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of FrameLayout in Android

Shulou Source: shulou.com Published: 2022-06-01 02:25:25 10月03日 Update

This article will explain in detail the example analysis of FrameLayout in Android. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Overview

FrameLayout layouts components in a cascading manner: only one of them can be displayed at a time. Similar to playing cards, only the top card can be seen when stacked together. FrameLayout provides a XML configuration property for components laid out in it: Android:layout_gravity. With this property, components laid out in FrameLayout can specify their center of gravity in the container, such as left, right, and so on, and all controls are displayed in the upper left corner of the screen by default.

Properties defined globally by FrameLayout

Exercise one

Implement the following layout

Code:

Exercise two

To achieve the mouse click on the picture, and then the effect of picture switch (4 pictures of your own choice)

Code:

Activity_main.xml

MainActivity.java

Package com.example.myapplication; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle;import android.view.View;import android.widget.ImageView;import android.widget.Toolbar; public class MainActivity extends AppCompatActivity implements View.OnClickListener {private ImageView p1, p3, Bundle savedInstanceState, p4; @ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); p1 = (ImageView) this.findViewById (R.id.p1) P1.setOnClickListener (this); p2 = (ImageView) this.findViewById (R.id.p2); p2.setOnClickListener (this); p3 = (ImageView) this.findViewById (R.id.p3); p3.setOnClickListener (this); p4 = (ImageView) this.findViewById (R.id.p4); p4.setOnClickListener (this);} @ Override public void onClick (View view) {int id= view.getId () Switch (id) {case R.id.p1: p1.setVisibility (View.GONE); p2.setVisibility (View.VISIBLE); break; case R.id.p2: p2.setVisibility (View.GONE); p3.setVisibility (View.VISIBLE); break Case R.id.p3: p3.setVisibility (View.GONE); p4.setVisibility (View.VISIBLE); break; case R.id.p4: p4.setVisibility (View.GONE); p1.setVisibility (View.VISIBLE); break } this is the end of this article on "sample Analysis of FrameLayout in Android". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Layout pictures properties articles components examples analysis code more good practical location global content container screen upper left corner poker poker controls Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Shulou Technology Huawei Redmi NVidia