I have a pie chart and mapview on the screen. Between chart and mapview, there is a small imageview. When imageview moves, chart and mapview are supposed to have grow and shrink. It works, but when I move imageview, app is shaking. I want their sizes to change smoothly. I think it is due to pie chart. How can I fix this? Thanks. Here is my Java code :
final LinearLayout aboveLinear = (LinearLayout) findViewById(R.id.aboveLinear); final LinearLayout belowLinear = (LinearLayout) findViewById(R.id.belowLinear); final ImageView imageView2 = (ImageView) findViewById(R.id.imageView2); detector = new GestureDetectorCompat(this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { if ( aboveLinear == null || belowLinear == null ) { return true; } distanceY*=-1; int height = aboveLinear.getHeight ( ) + mapview.getHeight ( ); ViewGroup.LayoutParams layoutParams = aboveLinear.getLayoutParams ( ); if ( ( int ) distanceY + layoutParams.height < minH ) layoutParams.height = minH; else if ( ( int ) distanceY + layoutParams.height > height - minH ) layoutParams.height = height - minH; else layoutParams.height = ( int ) distanceY + layoutParams.height; ViewGroup.LayoutParams layoutParams2 = belowLinear.getLayoutParams ( ); layoutParams2.height = height - layoutParams.height; aboveLinear.setLayoutParams ( layoutParams ); belowLinear.setLayoutParams ( layoutParams2 ); return true; } }); imageView2.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(final View view, final MotionEvent motionEvent) { return detector.onTouchEvent(motionEvent); } }); mapview = (MapView) findViewById(R.id.mapview); mapview.onCreate(savedInstanceState); chart1 = (PieChart) findViewById(R.id.chart1); chart1.setUsePercentValues(true); chart1.setDescription(""); chart1.setExtraOffsets(5, 10, 5, 5); chart1.setDragDecelerationFrictionCoef(0.95f); Here is my xml code :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" xmlns:mapbox="http://schemas.android.com/apk/res-auto" android:id="@+id/root"> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:id="@+id/aboveLinear"> <com.github.mikephil.charting.charts.PieChart android:id="@+id/chart1" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentTop="true" android:scaleType="fitXY"/> </LinearLayout> <ImageView android:id="@+id/imageView2" android:layout_width="match_parent" android:layout_height="25dp" android:layout_alignParentTop="true" android:clickable="true" android:scaleType="fitXY" android:src="@drawable/red"/> <LinearLayout android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:id="@+id/belowLinear"> <com.mapbox.mapboxsdk.maps.MapView android:layout_height="match_parent" android:scaleType="fitXY" android:id="@+id/mapview" android:layout_width="fill_parent" mapbox:access_token="@string/accessToken" mapbox:style_url="@string/style_mapbox_streets" mapbox:center_latitude="41.885" mapbox:center_longitude="-87.679" mapbox:zoom="12" mapbox:tilt="20"/> </LinearLayout> </LinearLayout>