Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of FrameLayout in Android

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report