- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在我的 Android 项目中使用 Google Maps V2。我已经(使用向导)创建了一个带有可滚动选项卡 + 滑动的 Activity ,在我的一个布局中我使用的是 SupportMapFragment,但是在 map 中我无法水平滚动 map ,当在 map 内滑动时它会显示另一种观点。这是我的代码:
主 Activity
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;
}
}
}
LocalizacaoPesquisadorActivity
public class LocalizacaoPesquisadorActivity extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_localizacao_pesquisador,
container, false);
System.out.println();
return rootView;
}
}
activity_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>
activity_localizacao_pesquisador.xml
<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>
我想拦截在 map 上的滑动 Action ,你怎么看?
最佳答案
首先,更新您的 Android SDK 并通过从 <android-sdk>\extras\android\support\v4\android-support-v4.jar
复制来确保您使用的是最新版本的 Android 支持库。 .旧版本的支持库无法正确处理此问题。
然后扩展 ViewPager 对象:
/**
* Extension of ViewPager that allows the user to move the map
* inside the fragment, but still supports swiping to the
* next fragment via "bezel swipe" (i.e., swiping from the edge)
*/
public class ViewPagerMapBevelScroll extends android.support.v4.view.ViewPager {
private static final int DEFAULT_SWIPE_MARGIN_WIDTH_DIP = 20;
private int swipeMarginWidth;
public ViewPagerMapBevelScroll(Context context) {
super(context);
setDefaultSwipeMargin(context);
}
public ViewPagerMapBevelScroll(Context context, AttributeSet attrs) {
super(context, attrs);
setDefaultSwipeMargin(context);
}
private void setDefaultSwipeMargin(final Context context) {
swipeMarginWidth = (int) (DEFAULT_SWIPE_MARGIN_WIDTH_DIP * context
.getResources().getDisplayMetrics().density);
}
@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x, int y) {
if (v instanceof ViewPagerMapBevelScroll) {
if (getCurrentItem() == SectionsPagerAdapter.MAP_TAB) {
return !isAllowedMapSwipe(x, dx);
}
}
return super.canScroll(v, checkV, dx, x, y);
}
/**
* Determines if the pointer movement event at x and moved pixels is
* considered an allowed swipe movement overriding the inner horizontal
* scroll content protection.
*
* @param x X coordinate of the active touch point
* @param dx Delta scrolled in pixels
* @return true if the movement should start a page swipe
*/
protected boolean isAllowedMapSwipe(final float x, final float dx) {
return ((x < swipeMarginWidth) && (dx > 0))
|| ((x > (getWidth() - swipeMarginWidth)) && (dx < 0));
}
}
然后,更改您的布局以使用 ViewPagerMapBevelScroll
(确保更改包名称以匹配 ViewPagerMapBevelScroll
对象的位置):
<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" >
然后,更改您的 SectionsPagerAdapter
添加 MAP_TAB
我们在 ViewPagerMapBevelScroll 中引用的值,并将其设置为等于包含 map 的选项卡的索引:
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);
}
...
}
如果您想查看完整的工作版本,请查看开源 GPSTest app .
isAllowedMapSwipe
的功劳方法转到 Martin Hochstrasser(参见 http://goo.gl/Hyl2E)
[2013 年 11 月 8 日更新] - 请注意,根据 BornToCode 对此答案的评论,最新的支持库为 ViewPager
和 Google Play 服务库,Android 3.0 (Honeycomb) 及更高版本不再需要此解决方法,但仍需要在 Android 2.3 (Gingerbread) 和 Android 2.2 (Froyo) 上获得正确的行为。
关于java - Android - map 不会水平滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17661084/
我目前正在研究一个项目欧拉问题(www.projecteuler.net),但遇到了一个绊脚石。其中一个问题提供了一个 20x20 的数字网格,并要求直线上 4 个数字的最大乘积。这条线可以是水平的、
我有两个表,我需要从每个表中选择一列。 这必须在单个查询中完成。 好消息是这两列以正确的方式排序,并且它们都包含相同数量的行。 现在,我知道我可以通过 rowid 加入两个表,但它很慢,因为它必须进行
我想在我的 iPad 应用程序中实现一个布局,该布局具有一个可左右滚动而不是上下滚动的合适 View : 所以而不是 第 1 行第 2 行第 3 行(垂直滚动)这将是 :第 1 行、第 2 行、第 3
我有五个尺寸的图像:600x30、600x30、600x30、600x30、810x30。它们的名称分别是:0.png、1.png、2.png、3.png、4.png。 如何使用 ImageMagic
我正在寻找一个选项来滚动多个列表(水平),如附件中的图片所示。您可以向左或向右滑动以进入下一个 ListView 。顶部应该有一些按钮可以单击或滚动 我尝试将 ListViews 放入类似此代码的内容
这些值之间是否存在数学关系?如果我知道 hFOV 和 vFOV,我可以计算对角 FOV 而不涉及焦距等其他值吗? 我的第一个想法是使用毕达哥拉斯定理,但也许这是错误的。 最佳答案 感兴趣的物理量是传感
我正在尝试在 game_width=640 和 game_height=480 的窗口内绘制网格。网格单元的数量是预定义的。我想在水平和垂直方向上均匀分布单元格。 void GamePaint(HDC
你好,我已经发布了我的 iphone 应用程序 Micro-Pitch,现在正在将它移植到 android 上。我不知道如何在 ScrollView 中画线,想知道我做错了什么。 这是我的 Scrol
如果您访问我的网站:www.ryancoughlin.com - 如果您在页面右侧看到 Google、Yahoo 等 RSS 按钮。我试图让它们均匀对齐,它们的图像高度都相同,我一直试图让它们均匀对齐
我想将此 Material 水平居中: 最佳答案 将 text-align:center 添加到您的 anchor 。我假设您的 zoom1 具有 display
我正在努力做到这一点,以便我的旋转木马可以与其他文本共享一个水平行,但由于某种原因它无法正常工作,当它设置为 40% 时它占据了 100% 的宽度。 我将在下面发布代码和屏幕截图。 在上图中,它显示了
问题来了。我正在尝试放置一些 彼此相邻的元素。 div 的宽度s 未指定,取决于它们的内容。我正在使用下面的 CSS 代码来定位 彼此相邻: #div{ height: 50px; f
我正在尝试使用这样的 Bootstrap 并排打印表格 但是当我尝试打印预览时,我得到了这个 我的代码如下。我尝试了所有可能的解决方案,但我不知道为什么我无法打印我看到的页面。请指导我解决这个问题。
我想知道是否可以在背景中使用两种不同的颜色,并通过 Bootstrap 在每一侧扩展 100%。 这是我的意思的截图, 左侧为红色,右侧为深色,为更大的屏幕放大 100%。有什么简单的解决方案吗? 最
我正在尝试制作一个包含所有事件的滚动触发的整个网站。我只需要帮助来实现这种效果: 我有一个网站,其中包含一些填满所有视口(viewport)的 div,我希望用户能够向下滚动到一个命名的 div,然后
我的代码是 Show All Show Valid Show Pending Save Clear Download As CSV 我希望那些输入日期和按钮在 class="buttons" di
我在玩这个想法: 在这个 block 中我有 2 作为按钮和 并尝试了 float荷兰国际集团他们让他们粘在一起。实现这种效果的主要思想是操纵 ul 的宽度/显示状态。或者只是菜单部分。 Log
这个问题在这里已经有了答案: How can I horizontally center an element? (134 个回答) 关闭 4 年前。
我遇到了一个 CSS 问题,需要帮助。我在目录中有许多不同大小的图像,我正在动态列出它们以显示以下 View :(我仅显示两个图像作为示例) 这是我的 HTML:
这个问题在这里已经有了答案: 关闭 9 年前。 Possible Duplicate: How can I make a horizontal ListView in Android? 我已经多次使
我是一名优秀的程序员,十分优秀!