Should only 1 view go in 1 Activity, in Android? [closed]
What is "best practice"? Should each view have its own Activity?开发者_Python百科 Never 2 views in 1 Activity?
No no no... each widget is a View. Each Activity should have a Layout and each Layout should have multiple Views.
So, imagine you have this layout XML file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View 1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="View 2" />
</LinearLayout>
Both of those TextView
s are Views. The LinearLayout
is a ViewGroup
and the whole thing makes up a Layout. An Activity
would bind to the Layout then you could get handles to any of the Views.
If you're asking whether each Activity
should have it's own layout then the answer is, generally speaking, yes.
I guess you can use tab widget. Please reference this "Hello, TabWidget". (http://developer.android.com/guide/tutorials/views/hello-tabwidget.html)
精彩评论