开发者

Multiple Views in one Activity (like Map and List)

开发者 https://www.devze.com 2023-04-11 12:13 出处:网络
I have been fiddling a bit with android the last few days. I have run into an issue when including views in other views.

I have been fiddling a bit with android the last few days. I have run into an issue when including views in other views.

When working with simple views, this is no problem, but as soon as the view has some fancy activity working with it, like ListActivity or MapActivity (when using google maps view)

Lets say that i need a list of some dynamic kind, and a google maps view in the same view. Since they both have a specific activity associated with it, how would i go about creating that?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:orientation="vertical" android:layout_width="fill_parent" android:id="@+id/linearLayout1" android:weightSum="1">
    <include android:id="@+id/include1" layout="@layout/list" android:layout_height="wrap_content"  android:lay开发者_运维技巧out_width="match_parent"></include>
    <include android:id="@+id/include2" layout="@layout/map" android:layout_width="match_parent" android:layout_height="wrap_content"></include>
</LinearLayout>

Should i use that Inflater thingy instead?

I have been searching for a solution to this problem, but i havent found any. Either my google fu is missing, or i'm looking at this the wrong way.

While writing this, and reading the related questions here on SO, i may have found the solution. Since the ListActivity and MapActivity is just extended Activities, instead of using the ListActivity and MapActivity that the android SDK provide, i should just use an ordinary Activity, and implement the stuff myself, or if possible, reuse their activities in my own activity?

Can anyone confirm this? :)

Thanks in advance :)


MapViews are not always inside MapActivities and ListViews are not always inside ListActivities. Those activities exist as starting points for other Activities that revolve around a single view type.

To answer your question: If you want an activity that contains both a ListView and a MapView you can simply add them to the root view group of the activity. Then simply implement the required methods to get the MapView and ListView working properly.

I'm not sure what you mean about having multiple view types in a single view. Usually people talk about adding views to view groups for example:

<LinearLayout ....>
    <Button ..../>
    <ImageView ..../>
</LinearLayout>

In this case you have a LinearLayout viewgroup that contains 2 views a Button and a ImageView. In Android it doesn't make sense to talk about a ImageView containing another view.

This leads me to think that the Title of you question should really be:

Multiple view types in one Activity (like Map and List)

0

精彩评论

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

关注公众号