2016-03-04 57 views
0

這阿爾卡特平板電腦的RelativeLayout演員錯誤是我的代碼:與Android

   WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE); 
       Display display = wm.getDefaultDisplay(); 
       Point size = new Point(); 
       display.getSize(size); 
       int height = size.x/3; 
       RelativeLayout.LayoutParams mParams = (RelativeLayout.LayoutParams) gridview.getLayoutParams(); 
       int rows = (int) Math.ceil(mAreas.size()/3.0); 
       mParams.height = rows * height; 
       gridview.setLayoutParams(mParams); 

它在任何設備工作正常,但我想它在阿爾卡特平板電腦以及由於某種原因,我得到這個錯誤,任何建議?,它看起來像alcatel改變了類的一些奇怪的原因,並停止像其他的Android發行版一樣工作?

FATAL EXCEPTION: main 
     java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.widget.AbsListView$LayoutParams 
     at android.widget.GridView.onMeasure(GridView.java:1043) 
     at android.view.View.measure(View.java:15784) 
     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:681) 
     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461) 
     at android.view.View.measure(View.java:15784) 
     at android.widget.ListView.setupChild(ListView.java:1927) 
     at android.widget.ListView.makeAndAddView(ListView.java:1842) 
     at android.widget.ListView.fillDown(ListView.java:678) 
     at android.widget.ListView.fillSpecific(ListView.java:1339) 
     at android.widget.ListView.layoutChildren(ListView.java:1675) 
     at android.widget.AbsListView.onLayout(AbsListView.java:2053) 
     at android.view.View.layout(View.java:14252) 
     at android.view.ViewGroup.layout(ViewGroup.java:4490) 
     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021) 
     at android.view.View.layout(View.java:14252) 
     at android.view.ViewGroup.layout(ViewGroup.java:4490) 
     at android.widget.FrameLayout.onLayout(FrameLayout.java:448) 
     at android.view.View.layout(View.java:14252) 
     at android.view.ViewGroup.layout(ViewGroup.java:4490) 
     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1670) 
     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1528) 
     at android.widget.LinearLayout.onLayout(LinearLayout.java:1441) 
     at android.view.View.layout(View.java:14252) 
     at android.view.ViewGroup.layout(ViewGroup.java:4490) 
     at android.widget.FrameLayout.onLayout(FrameLayout.java:448) 
     at android.view.View.layout(View.java:14252) 
     at android.view.ViewGroup.layout(ViewGroup.java:4490) 
     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2231) 
     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1995) 
     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1181) 
     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4943) 
     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:776) 
     at android.view.Choreographer.doCallbacks(Choreographer.java:579) 
     at android.view.Choreographer.doFrame(Choreographer.java:548) 
     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:762) 
     at android.os.Handler.handleCallback(Handler.java:800) 
     at android.os.Handler.dispatchMessage(Handler.java:100) 
     at android.os.Looper.loop(Looper.java:194) 
     at android.app.ActivityThread.main(ActivityThread.java:5413) 
     at java.lang.reflect.Method.invokeNative(Native Method) 
     at java.lang.reflect.Method.invoke(Method.java:525) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:834) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 
     at dalvik.system.NativeStart.main(Native Method) 

的XML:

<?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:orientation="vertical" 
    android:background="@color/white"> 
    <LinearLayout 
     android:id="@+id/time_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 
     <TextView 
      android:id="@+id/time" 
      android:layout_gravity="center" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="34sp" 
      android:layout_marginTop="@dimen/irrigation_text_vertical_margin" 
      android:layout_marginStart="@dimen/irrigation_text_horizontal_margin" 
      android:layout_marginLeft="@dimen/irrigation_text_horizontal_margin" 
      android:text="@string/placeholder" 
      android:textColor="@color/accent"/> 
     <TextView 
      android:id="@+id/status" 
      android:layout_gravity="center" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:layout_marginTop="@dimen/irrigation_text_vertical_margin" 
      android:layout_marginStart="@dimen/irrigation_text_horizontal_margin" 
      android:layout_marginLeft="@dimen/irrigation_text_horizontal_margin" 
      android:textColor="@color/accent"/> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/duration_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_below="@id/time_layout"> 
     <TextView 
      android:textColor="@color/accent" 
      android:id="@+id/duration" 
      android:layout_gravity="center" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:textSize="20sp" 
      android:layout_marginStart="@dimen/irrigation_text_horizontal_margin" 
      android:layout_marginLeft="@dimen/irrigation_text_horizontal_margin" 
      android:text="@string/placeholder"/> 
     <SeekBar 
      android:id="@+id/duration_seek" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:max="20" /> 
    </LinearLayout> 
    <LinearLayout 
     android:id="@+id/week" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_below="@id/duration_layout" 
     android:layout_marginTop="10dp" 
     android:layout_margin="5dp"> 
     <TextView 
      android:textColor="@color/accent" 
      android:id="@+id/m" 
      android:layout_width="35dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/bg_circle_true" 
      android:gravity="center" 
      android:layout_margin="5dp" 
      android:text="@string/monday_short"/> 
     <TextView 
      android:textColor="@color/accent" 
      android:id="@+id/t" 
      android:layout_width="35dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/bg_circle_true" 
      android:gravity="center" 
      android:layout_margin="5dp" 
      android:text="@string/tuesday_short"/> 
     <TextView 
      android:textColor="@color/accent" 
      android:id="@+id/w" 
      android:layout_width="35dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/bg_circle_true" 
      android:gravity="center" 
      android:layout_margin="5dp" 
      android:text="@string/wednesday_short"/> 
     <TextView 
      android:textColor="@color/accent" 
      android:id="@+id/th" 
      android:layout_width="35dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/bg_circle_true" 
      android:gravity="center" 
      android:layout_margin="5dp" 
      android:text="@string/thursday_short"/> 
     <TextView 
      android:textColor="@color/accent" 
      android:id="@+id/f" 
      android:layout_width="35dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/bg_circle_true" 
      android:gravity="center" 
      android:layout_margin="5dp" 
      android:text="@string/friday_short"/> 
     <TextView 
      android:textColor="@color/accent" 
      android:id="@+id/s" 
      android:layout_width="35dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/bg_circle_true" 
      android:gravity="center" 
      android:layout_margin="5dp" 
      android:text="@string/saturday_short"/> 
     <TextView 
      android:textColor="@color/accent" 
      android:id="@+id/su" 
      android:layout_width="35dp" 
      android:layout_height="wrap_content" 
      android:background="@drawable/bg_circle_true" 
      android:gravity="center" 
      android:layout_margin="5dp" 
      android:text="@string/sunday_short"/> 
    </LinearLayout> 
    <Button 
     android:layout_below="@+id/week" 
     android:id="@+id/area_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="20sp" 
     android:text="Manage areas" 
     style="?android:attr/buttonBarButtonStyle" 
     android:drawableLeft="@drawable/ic_expand" 
     android:drawableStart="@drawable/ic_expand" 
     android:textColor="@color/primary_dark"/> 
    <ImageButton 
     android:contentDescription="@string/delete_irrigation_cd" 
     android:id="@+id/trash" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentEnd="true" 
     android:layout_below="@+id/week" 
     android:layout_width="45dp" 
     android:layout_height="45dp" 
     android:src="@drawable/btn_trash" 
     android:scaleType="fitCenter" 
     style="?android:attr/buttonBarButtonStyle" 
     android:layout_marginBottom="10dp" 
     android:layout_marginRight="10dp" 
     android:layout_marginEnd="10dp"/> 
    <GridView 
     android:visibility="gone" 
     android:paddingTop="1dp" 
     android:paddingBottom="1dp" 
     android:background="#DBEEFB" 
     android:layout_below="@+id/trash" 
     android:id="@+id/area_grid" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:numColumns="3" 
     android:stretchMode="columnWidth" 
     android:gravity="center" 
     android:horizontalSpacing="2dp" 
     android:verticalSpacing="1dp" 
     android:scrollbars="none"/> 
</RelativeLayout> 

設法解決它,問題不是我貼的代碼裏面,那是在我被取出後用庫類,它開始爲每一個工作正常設備感謝所有的輸入壽命!

+0

你想轉換** ListView ** ** ** RelatvieLayout **,這是不可能的 – Amir

+0

@Amir nope我不這樣做,在任何時候,getLayoutParams返回父類的參數,而不是網格參數,所以我沒有得到網格參數,但父視圖參數極其確實RelativeLayout(這就是爲什麼這個工作在我測試過的所有設備上都會使用這個alcatel平板電腦) – Nero

+0

什麼是GridView的父項? – Andy

回答

0

設法解決它,問題不是我貼的代碼裏面,它是在一個庫類,我是使用後,刪除它,它開始工作正常的每個設備感謝所有輸入壽!

0

的錯誤是因爲你想投你的LayoutParams到了錯誤的類型,請嘗試:

AbsListView.LayoutParams mParams = (AbsListView.LayoutParams) gridview.getLayoutParams(); 
+0

不,這是純粹的錯誤,它需要被鑄造到父母layoutParams,而不是一個隨機的參數,我試過這反正b4張貼,但正如我所期望的,我得到了一個錯誤 – Nero

+0

尼祿,發揮不錯。 – Andy

+0

@Andy sory如果聽起來不好聽,我不會說英語。 – Nero