What is the difference between view and activity in android development?

后端 未结 7 749
南旧
南旧 2021-02-04 01:37

When do I need to create a new activity and when do I need to change the view?

My app needs to do:

Screen #1

two big buttons(sort of menu)

Scr

相关标签:
7条回答
  • 2021-02-04 02:02

    The "right" way to do it is to use Activity for each screen and use the <include> tag for the menu you would like to be in all screens.

    This way you will have the "back" button act as it should be and it would be easier for you to handle when switching screens.

    To use the , you should put the things you want to reuse into extra files. Then you can use it as follows:

    <!-- my_header.xml -->
    <?xml version="1.0" encoding="UTF-8"?>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/text01"/>
    

    In another file include it with:

    <include layout="@layout/my_header" />
    <!-- your other stuff -->
    
    0 讨论(0)
  • 2021-02-04 02:03

    View is Display System of Android where you define layout to put subclasses of View in it eg. Buttons, Images etc. But Activity is Screen System of Android where you put display as well as user-interaction,(or whatever which can be contained in full-screen Window.)

    Now for your question,you are creating full window screen#2 ,screen#3... ,so it is activity. In these screen you can define layout/or Views.

    I hope it helps.

    0 讨论(0)
  • 2021-02-04 02:11

    A View in Android is a widget that displays something. Buttons, listviews, imageviews, etc. are all subclasses of View. When you say "change view" I assume you mean change the layout by using setContentView(). This usually only needs to be done once per activity. An Activity is basically what you are referring to as a screen. To answer your question, it sounds like you need four separate activities (one for each screen).

    0 讨论(0)
  • 2021-02-04 02:11

    You should create 4 xml files... and play Around changing content using setContentView(R.Layout.yourxml);..

    you can do this using single Activity.. it depends on how big the class becomes.. if its too heavy with lot of different stuff, for the sake of cohision and to avoid coupling use multiple Activities

    0 讨论(0)
  • 2021-02-04 02:19

    activity is like canvas where you put your drawing as view.Yes you can set all above four view in single activity but it will depend how you handle it and does your app needs it to be done like this.

    0 讨论(0)
  • 2021-02-04 02:23

    You should create separate activities for you screens. Android handles the back button of the device by popping the current activity out from the stack and displaying the last one. So if for example the user wants to return to screen 2 for another selection, the back button does this.

    0 讨论(0)
提交回复
热议问题