Răsfoiți Sursa

1.修改Android Apex Mobile KPI宽高计算不正确。

Pen Li 8 ani în urmă
părinte
comite
fd7800b401

+ 1 - 3
Apex Mobile/app/src/main/java/com/usai/apex/KPI/KPICell.java

@@ -48,10 +48,8 @@ public class KPICell extends RelativeLayout implements View.OnClickListener,KPIL
     private KPIListView mItemListView;
     private ValueAnimator mAnimation;
 
-    public void init(int w, int h) {
+    public void init() {
 
-        mWidth = w;
-        mHeight = h;
         mCell = this;
 
         mShipTV = findViewById(R.id.shipmentTV);

+ 11 - 8
Apex Mobile/app/src/main/java/com/usai/apex/KPI/PieChartView.java

@@ -682,16 +682,19 @@ public class PieChartView extends View {
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
 
-        KPICell p = (KPICell) getParent();
-        int w = p.getKPIWidth();
-
-        int leftInterval = dp2px(getContext(),60);
-        int rightInterval = dp2px(getContext(),60);
+//        KPICell p = (KPICell) getParent();
+//        int w = p.getKPIWidth();
+//
+//        int leftInterval = dp2px(getContext(),60);
+//        int rightInterval = dp2px(getContext(),60);
+//
+//        int pieW = (w - leftInterval - rightInterval);
 
-        int pieW = (w - leftInterval - rightInterval);
+//        widthMeasureSpec = MeasureSpec.makeMeasureSpec(pieW, MeasureSpec.EXACTLY);
+//        heightMeasureSpec = MeasureSpec.makeMeasureSpec(pieW, MeasureSpec.EXACTLY);
 
-        widthMeasureSpec = MeasureSpec.makeMeasureSpec(pieW, MeasureSpec.EXACTLY);
-        heightMeasureSpec = MeasureSpec.makeMeasureSpec(pieW, MeasureSpec.EXACTLY);
+        int width = MeasureSpec.getSize(widthMeasureSpec);
+        heightMeasureSpec = MeasureSpec.makeMeasureSpec(width,MeasureSpec.EXACTLY);
 
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
     }

+ 1 - 12
Apex Mobile/app/src/main/java/com/usai/apex/mainframe/KPIFragment.java

@@ -106,21 +106,12 @@ public class KPIFragment extends Fragment implements KPICell.KPIListener {
         super.onDestroyView();
     }
 
-    private int mWidth,mHeight;
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container,
                              Bundle savedInstanceState) {
         // Inflate the layout for this fragment
         View root = inflater.inflate(R.layout.fragment_kpi, container, false);
 
-        if (savedInstanceState != null) {
-            mWidth = savedInstanceState.getInt("width");
-            mHeight = savedInstanceState.getInt("height");
-        } else {
-            mWidth = container.getMeasuredWidth();
-            mHeight = container.getMeasuredHeight();
-        }
-
         mContext = getContext();
         self = this;
 
@@ -237,8 +228,6 @@ public class KPIFragment extends Fragment implements KPICell.KPIListener {
         if (mData != null) {
             outState.putString("KPIData",mData.toString());
             outState.putInt("currentKPI",currentKPI);
-            outState.putInt("width",mWidth);
-            outState.putInt("height",mHeight);
         }
         mKPIArr.clear();
         mAdapter.notifyDataSetChanged();
@@ -476,7 +465,7 @@ public class KPIFragment extends Fragment implements KPICell.KPIListener {
             KPICell cell = null;
             if (mReusePool.isEmpty()) {
                 cell = (KPICell) LayoutInflater.from(mContext).inflate(R.layout.kpi_cell,null);
-                cell.init(mWidth,mHeight);
+                cell.init();
             } else {
                 cell = mReusePool.get(0);
                 mReusePool.remove(cell);

+ 3 - 1
Apex Mobile/app/src/main/res/layout/kpi_cell.xml

@@ -59,10 +59,12 @@
 
     <com.usai.apex.KPI.PieChartView
         android:id="@+id/chart_view"
-        android:layout_width="300dp"
+        android:layout_width="match_parent"
         android:layout_height="300dp"
         android:layout_below="@+id/selectionTV"
         android:layout_marginTop="5dp"
+        android:layout_marginLeft="60dp"
+        android:layout_marginRight="60dp"
         android:layout_centerHorizontal="true"
         android:background="#00000000"/>