Android的谷歌地图API V2 - 按钮上方片段 [英] Android Google Map API V2 - Buttons above fragment

查看:127
本文介绍了Android的谷歌地图API V2 - 按钮上方片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经得到了一个地图,以显示在屏幕上。我想创建地图上方的按钮,然后添加行动这一点。例如。该按钮将改变地图的位置。我基本上想我的code适应这个: https://www.youtube .COM /手表?v = awX5T-EwLPc 。不过,我使用延伸片段活动,这打乱了一切。

I have managed to get a map to show on the screen. I am trying to create buttons above the map and then add actions to this. E.g. the button will change the location of the map. I am basically trying to adapt my code to this: https://www.youtube.com/watch?v=awX5T-EwLPc. However, I am using "extends Fragment Activity" which messes everything up.

我的问题:我无法创建地图上方的按钮时,它被放置在地图中。我试图创建地图上面的一个按钮,并指定code这样我就可以移动到地图等。这里的位置是我的code:

My problem: I cannot create a button above the map, it is placed inside the map. I am trying to create a button above the map, and assign code so I can move to a location on the map etc. Here is my code:

package com.example.theapp;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends FragmentActivity implements OnClickListener
{

    Button button;
    TextView text;

   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_main);

        button=(Button)findViewById(R.id.button1);
        text=(TextView)findViewById(R.id.textView1);
   }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        text.setText("The button worked!");

    }
}

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/map"
        android:layout_alignTop="@+id/map"
        android:text="Button" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button1"
        android:layout_alignBottom="@+id/button1"
        android:layout_alignRight="@+id/map"
        android:layout_marginRight="39dp"
        android:text="TextView" />

</RelativeLayout>

从code,我的应用程序显示在地图和文本视图上的一个按钮。当您单击按钮,它的意思更改文本,但它不会做任何事情。我研究的教程和它的外观,我会创建多个片段?

From the code, my app displays a button on the map and a text view. When you click the button, its meant to change the text, but it doesn't do anything. I have researched tutorials and by the looks of it, I will have to create multiple fragments?

问:我如何将能够创建一个页面上的一个按钮,即会那么针点在地图上的用户

Question: How would I be able to create a button on that page, that will then pin point the user on the map?

感谢您提前。

推荐答案

您没有设置任何功能按钮...你应该使用

You are not setting any functionality to the Button... You should use

button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                text.setText("that's how you do it!");
            }
        });

这篇关于Android的谷歌地图API V2 - 按钮上方片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆