我a,目前在MapActivity中获取设备的当前位置(lat,lng).现在我想让用户移动地图,同时将标记保持在中心位置.这意味着无论何时移动地图,都将更新当前位置.(对?)
我按照这个android如何在标记下移动地图以及如何在地图上附加像Uber和Lyft这样的灵活标记?但无法明确我的观念.
Activity_map.xml(这里我添加了ImageView)
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/gps"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我的MapActivity如下
public class MapActivity extends FragmentActivity implements OnMapReadyCallback,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener,
LocationListener,GoogleMap.OnInfoWindowClickListener{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_map);
// int x =_st.jsonArray.length();
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
checkLocationPermission();
}
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
fragmentOnMap = (FragmentOnMap)getFragmentManager().findFragmentById(R.id.fragment_bottom);
getFragmentManager().beginTransaction().hide(fragmentOnMap); …
Run Code Online (Sandbox Code Playgroud) 我试图将动画添加到从底部单击按钮时出现的片段中。
片段布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:background="@color/wallet_holo_blue_light"
android:layout_gravity="center"
android:text="This is a fragmentt layout"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
滑动up.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime">
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime"
android:fromYDelta="50.0%p"
android:interpolator="@android:anim/decelerate_interpolator"
android:toYDelta="30" />
</set>
Run Code Online (Sandbox Code Playgroud)
在这里调用:
public void onClick(View view) {
if(view == button ){
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
FragmentOnMap hello = new FragmentOnMap();
fragmentTransaction.add(R.id.fragment_container, hello, "HELLO");
fragmentTransaction.setCustomAnimations(R.animator.slide_up,0);
fragmentTransaction.commit();
}
}
Run Code Online (Sandbox Code Playgroud)
Android Fragments和动画显示了如何上下滑动,我只是将片段动画化。因此,我的问题是setcustomanimation()函数的第二个参数
我尝试fragmentTransaction.setCustomAnimations()
在提交前使用,但没有帮助。
它确实出现在底部,但是没有过渡效果。任何指导都是有用的。谢谢