开发者

Should only 1 view go in 1 Activity, in Android? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜