Kaynağa Gözat

1.修改Android Apex KPI字体大小适配屏幕。

Pen Li 8 yıl önce
ebeveyn
işleme
30f41c2d27

+ 16 - 2
Apex Mobile/app/src/main/java/com/usai/apex/KPI/KPICell.java

@@ -8,6 +8,7 @@ import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.util.AttributeSet;
 import android.util.Log;
+import android.util.TypedValue;
 import android.view.GestureDetector;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
@@ -47,7 +48,7 @@ public class KPICell extends RelativeLayout implements KPIListView.KPIListViewTo
     private ArrayList<PieChartView.ChartItem> mChartItems;
     private PieChartView mChartView;
     private ImageButton mPreBtn,mNextBtn;
-    private TextView mShipTV,mContainerTV,mTeuTV,mSelectionTV;
+    private TextView mMonthTV,mShipTV,mContainerTV,mTeuTV,mSelectionTV;
     private KPIListView mItemListView;
     private ValueAnimator mAnimation;
 
@@ -56,7 +57,7 @@ public class KPICell extends RelativeLayout implements KPIListView.KPIListViewTo
         mCell = this;
 
         mDetector = new GestureDetector(getContext(), new GestureListener());
-
+        mMonthTV = findViewById(R.id.monthTV);
         mShipTV = findViewById(R.id.shipmentTV);
         mContainerTV = findViewById(R.id.containerTV);
         mTeuTV = findViewById(R.id.teuTV);
@@ -261,6 +262,14 @@ public class KPICell extends RelativeLayout implements KPIListView.KPIListViewTo
 
         mWidth = w;
         mHeight = h;
+
+        float ratio = px2dp(getContext(),w) / px2dp(getContext(),720.0f);
+        float textSize = 17.0f;
+        mMonthTV.setTextSize(TypedValue.COMPLEX_UNIT_SP,ratio * textSize);
+        mShipTV.setTextSize(TypedValue.COMPLEX_UNIT_SP,ratio * textSize);
+        mContainerTV.setTextSize(TypedValue.COMPLEX_UNIT_SP,ratio * textSize);
+        mTeuTV.setTextSize(TypedValue.COMPLEX_UNIT_SP,ratio * textSize);
+        mSelectionTV.setTextSize(TypedValue.COMPLEX_UNIT_SP,ratio * textSize);
     }
 
 
@@ -331,6 +340,11 @@ public class KPICell extends RelativeLayout implements KPIListView.KPIListViewTo
         return (int) (dpValue * scale + 0.5f);
     }
 
+    public static int px2dp(Context context, float pxValue) {
+        float scale = context.getResources().getDisplayMetrics().density;
+        return (int) (pxValue / scale + 0.5f);
+    }
+
     private KPIItemAdapter mAdapter;
 
 //    @Override

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

@@ -15,7 +15,7 @@
         android:layout_marginLeft="5dp"
         android:text="This Month"
         android:textColor="@android:color/black"
-        android:textSize="12sp"/>
+        />
 
     <TextView
         android:id="@+id/shipmentTV"
@@ -23,7 +23,6 @@
         android:layout_height="wrap_content"
         android:layout_alignLeft="@id/monthTV"
         android:layout_below="@+id/monthTV"
-        android:textSize="12sp"
         android:text="Shipment 552"/>
 
     <TextView
@@ -34,7 +33,6 @@
         android:layout_toRightOf="@id/shipmentTV"
         android:layout_alignTop="@id/shipmentTV"
         android:layout_marginLeft="5dp"
-        android:textSize="12sp"
         android:text="Container 334"/>
 
     <TextView
@@ -45,7 +43,6 @@
         android:layout_toRightOf="@id/containerTV"
         android:layout_alignTop="@id/containerTV"
         android:layout_marginLeft="5dp"
-        android:textSize="12sp"
         android:text="TEU 888"/>
 
     <TextView