gpt4 book ai didi

android - 从底部滑动 View 到另一个布局

转载 作者:太空狗 更新时间:2023-10-29 14:53:51 27 4
gpt4 key购买 nike

我的应用程序有一个显示谷歌地图和当前位置的父布局,还有一个子布局,它从屏幕底部向上移动到谷歌地图,但只到屏幕的一半。我设法用以下代码完成了这一切。

上下滑动动画:

slide_down.xml

 <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="yFraction"
android:valueType="floatType"
android:valueFrom="0.58"
android:valueTo="1.0"
android:duration="@android:integer/config_mediumAnimTime"/>
<objectAnimator
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="alpha"
android:valueType="floatType"
android:valueFrom="1"
android:valueTo="0"
android:duration="@android:integer/config_mediumAnimTime"/>
</set>

slide_up.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<objectAnimator
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="yFraction"
android:valueType="floatType"
android:valueFrom="1.0"
android:valueTo="0.58"
android:duration="@android:integer/config_mediumAnimTime"/>
<objectAnimator
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:propertyName="alpha"
android:valueType="floatType"
android:valueFrom="0.58"
android:valueTo="1.0"
android:duration="@android:integer/config_mediumAnimTime"/>
</set>

主要 Activity :

     public class MainActivity extends FragmentActivity implements LocationListener{

GoogleMap googleMap;
private static final String LIST_FRAGMENT_TAG = "list_fragment";
Location mlocation;
String mLastUpdateTime;
double latitude;
double longitude;
int Radius = 100;
Boolean flag = false ;



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

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.maps);
googleMap = mapFragment.getMap();
googleMap.setMyLocationEnabled(true);

LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

Criteria criteria = new Criteria();
String bestProvider = locationManager.getBestProvider(criteria, true);
mlocation = locationManager.getLastKnownLocation(bestProvider);
if (mlocation != null) {
onLocationChanged(mlocation);
}
locationManager.requestLocationUpdates(bestProvider, 20000, 0, this);

}

@Override
public void onLocationChanged(Location location) {
mlocation = location;
latitude = location.getLatitude();

longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
long atTime = mlocation.getTime();
mLastUpdateTime = DateFormat.getTimeInstance().format(new Date(atTime));

googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
View marker = ((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.custom_marker_layout, null);

CameraPosition INIT =
new CameraPosition.Builder()
.target(latLng)
.zoom(17.5F)
.bearing(300F) // orientation
.tilt(50F) // viewing angle
.build();
googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(INIT));

googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 13));

googleMap.addMarker(new MarkerOptions()
.position(latLng)
// .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE))
.icon(BitmapDescriptorFactory.fromBitmap(createDrawableFromView(this, marker)))
.title(getAdress())
.snippet("Radius: " + Radius)).showInfoWindow();

googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

@Override
public boolean onMarkerClick(Marker marker) {
flag = true;
toggleList();
return true;
}

});

if(flag == false){
googleMap.getUiSettings().setAllGesturesEnabled(true);

}

private void toggleList() {
Fragment f = getFragmentManager().findFragmentByTag(LIST_FRAGMENT_TAG);
googleMap.getUiSettings().setAllGesturesEnabled(true);




if (f != null) {
getFragmentManager().popBackStack();
} else {
getFragmentManager().beginTransaction()
.setCustomAnimations(R.animator.slide_up,
R.animator.slide_down,
R.animator.slide_up,
R.animator.slide_down)
.add(R.id.list_fragment_container, SlidingListFragment
.instantiate(this, SlidingListFragment.class.getName()),
LIST_FRAGMENT_TAG
)


.addToBackStack(null).commit();
googleMap.getUiSettings().setAllGesturesEnabled(false);

}

子布局

<?xml version="1.0" encoding="utf-8"?>

<com.trickyandroid.fragmenttranslate.app.view.SlidingRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/hidden_panel"
android:background="#ffffffff">

<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</com.trickyandroid.fragmenttranslate.app.view.SlidingRelativeLayout>

父布局

    <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"
tools:context="com.trickyandroid.fragmenttranslate.app.MainActivity">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/maps"
class="com.google.android.gms.maps.SupportMapFragment"/>

<FrameLayout
android:id="@+id/list_fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</RelativeLayout>

Problem is

如果 map 是放大扩展如果子布局向上滑动那么我的 map 标记隐藏在子布局后面。我想在这种情况下, 我的 map 应该很少自动向上滑动。

Just like Whatsspp chat window . When we click for keyboard in it , chat window slide upward automatically or Friend Locator App .

最佳答案

我认为您应该先缩放到 map 中的标记,然后显示向上滑动动画。

您可以使用此链接缩放到某个位置。

Google Maps v2 - set both my location and zoom in

CameraUpdate center=
CameraUpdateFactory.newLatLng(new LatLng(40.76793169992044,
-73.98180484771729));
CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);

map.moveCamera(center);
map.animateCamera(zoom);

关于android - 从底部滑动 View 到另一个布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33032603/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com