Java 安卓-地图不';t水平滚动
我在Android项目中使用谷歌地图V2。我(使用向导)创建了一个带有可滚动选项卡+滑动的活动,在我的一个布局中,我使用SupportMapFragment,但在地图中,我无法水平滚动地图,当在地图中滑动时,它会显示另一个视图。这是我的密码: main活动Java 安卓-地图不';t水平滚动,java,android,google-maps,google-maps-api-2,Java,Android,Google Maps,Google Maps Api 2,我在Android项目中使用谷歌地图V2。我(使用向导)创建了一个带有可滚动选项卡+滑动的活动,在我的一个布局中,我使用SupportMapFragment,但在地图中,我无法水平滚动地图,当在地图中滑动时,它会显示另一个视图。这是我的密码: main活动 public class MainActivity extends FragmentActivity { private List<Fragment> paginas; /** * The {
public class MainActivity extends FragmentActivity {
private List<Fragment> paginas;
/**
* The {@link android.support.v4.view.PagerAdapter} that will provide
* fragments for each of the sections. We use a
* {@link android.support.v4.app.FragmentPagerAdapter} derivative, which
* will keep every loaded fragment in memory. If this becomes too memory
* intensive, it may be best to switch to a
* {@link android.support.v4.app.FragmentStatePagerAdapter}.
*/
SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if(paginas==null){
paginas = new ArrayList<Fragment>();
paginas.add(new LocalizacaoPesquisadorActivity());
paginas.add(new VotosPorRegiaoActivity());
}
// Create the adapter that will return a fragment for each of the three
// primary sections of the app.
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
/**
* A {@link FragmentPagerAdapter} that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
switch (position) {
case 0:
return paginas.get(0);
case 1:
return paginas.get(1);
default: return null;
}
}
@Override
public int getCount() {
// Show 3 total pages.
return paginas.size();
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_activity_localizacao_pesquisador).toUpperCase(l);
case 1:
return getString(R.string.title_activity_votos_por_regiao).toUpperCase(l);
}
return null;
}
}
}
活动\u main.xml
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:textColor="#fff" />
</android.support.v4.view.ViewPager>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res=auto"
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=".LocalizacaoPesquisadorActivity" >
<EditText
android:id="@+id/editTextDataLocalizacaoPesquisador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:inputType="none"
android:hint="Data"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"/>
<Spinner
android:id="@+id/spinnerHorarioLocalizacaoPesquisador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editTextDataLocalizacaoPesquisador"
android:layout_alignRight="@+id/editTextDataLocalizacaoPesquisador"
android:layout_below="@+id/editTextDataLocalizacaoPesquisador"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp" />
<Button
android:id="@+id/buttonAtualizarLocalizacaoPesquisador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editTextDataLocalizacaoPesquisador"
android:layout_alignRight="@+id/editTextDataLocalizacaoPesquisador"
android:layout_below="@+id/spinnerHorarioLocalizacaoPesquisador"
android:text="Atualizar"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:onClick="atuarlizarMapaLocalizacaoPesquisador" />
<fragment android:id="@+id/mapaLocalizacaoPesquisador"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_below="@+id/buttonAtualizarLocalizacaoPesquisador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/buttonAtualizarLocalizacaoPesquisador"
android:layout_alignRight="@+id/buttonAtualizarLocalizacaoPesquisador"
android:layout_alignParentBottom="true"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
map:cameraTargetLat="-23.531152"
map:cameraTargetLng="-46.789876"
map:cameraZoom="1"
/>
</RelativeLayout>
activity\u localizacao\u pesquisador.xml
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:textColor="#fff" />
</android.support.v4.view.ViewPager>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res=auto"
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=".LocalizacaoPesquisadorActivity" >
<EditText
android:id="@+id/editTextDataLocalizacaoPesquisador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:inputType="none"
android:hint="Data"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"/>
<Spinner
android:id="@+id/spinnerHorarioLocalizacaoPesquisador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editTextDataLocalizacaoPesquisador"
android:layout_alignRight="@+id/editTextDataLocalizacaoPesquisador"
android:layout_below="@+id/editTextDataLocalizacaoPesquisador"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp" />
<Button
android:id="@+id/buttonAtualizarLocalizacaoPesquisador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editTextDataLocalizacaoPesquisador"
android:layout_alignRight="@+id/editTextDataLocalizacaoPesquisador"
android:layout_below="@+id/spinnerHorarioLocalizacaoPesquisador"
android:text="Atualizar"
android:layout_marginTop="4dp"
android:layout_marginBottom="4dp"
android:onClick="atuarlizarMapaLocalizacaoPesquisador" />
<fragment android:id="@+id/mapaLocalizacaoPesquisador"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_below="@+id/buttonAtualizarLocalizacaoPesquisador"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/buttonAtualizarLocalizacaoPesquisador"
android:layout_alignRight="@+id/buttonAtualizarLocalizacaoPesquisador"
android:layout_alignParentBottom="true"
android:layout_marginBottom="4dp"
android:layout_marginTop="4dp"
map:cameraTargetLat="-23.531152"
map:cameraTargetLng="-46.789876"
map:cameraZoom="1"
/>
</RelativeLayout>
我想在地图上拦截刷卡操作时,您会怎么想?首先,更新您的Android SDK,并通过从
复制确保您正在使用最新版本的Android支持库
“允许映射滑动”方法的归功于Martin Hochstrasser(请参阅)
[更新日期:2013年11月8日]-请注意,根据BornToCode对该答案的评论,借助最新的带有ViewPager
的支持库和Google Play Services库,Android 3.0(蜂巢)及更高版本不再需要此解决方案,但仍然需要在Android 2.3(姜饼)上获得正确的行为和Android 2.2(Froyo)。首先,更新您的Android SDK,并通过从复制确保您正在使用最新版本的Android支持库
“允许映射滑动”方法的归功于Martin Hochstrasser(请参阅)
[更新日期:2013年11月8日]-请注意,根据BornToCode对该答案的评论,借助最新的带有ViewPager
的支持库和Google Play Services库,Android 3.0(蜂巢)及更高版本不再需要此解决方案,但仍然需要在Android 2.3(姜饼)上获得正确的行为和Android 2.2(Froyo)。可能重复的可能重复的可能重复的我认为默认的滑动速度也可能是20dp(参考)。一个问题:哪一个最有意义,v instanceof ViewPagerMapBevelScroll
或v==this
?@BornToCode好的一点,我将把这个示例改为20dp,并在我的应用程序中尝试。我记得它应该是“instanceof”,但快速看一眼,我不记得为什么。你试过“==this”吗?仅供参考,我发现对于最新的ViewPager
和Google Play Services库来说,做这样的工作是不必要的。但是,我不知道为什么它在姜饼中不起作用,所以我仍然需要做这样的工作:)。ViewPagerMapBevelScroll可以为带有谷歌地图的viewpagers添加一个边距。谢谢。我想默认的滑动速度也可能是20dp(参考)。一个问题:哪一个最有意义,v instanceof ViewPagerMapBevelScroll
或v==this
?@BornToCode好的一点,我将把这个示例改为20dp,并在我的应用程序中尝试。我记得它应该是“instanceof”,但快速看一眼,我不记得为什么。你试过“==this”吗?仅供参考,我发现对于最新的ViewPager
和Google Play Services库来说,做这样的工作是不必要的。但是,我不知道为什么它在姜饼中不起作用,所以我仍然需要做这样的工作:)。ViewPagerMapBevelScroll可以为带有谷歌地图的viewpagers添加边距。谢谢。
<com.your.package.ViewPagerMapBevelScroll
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
public static final int MAP_TAB = 0; // Set this equal to
// the index of your map tab
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
...
}