0

目的

04-05 09:19:44.915: E/AndroidRuntime(26483): FATAL EXCEPTION: main 
04-05 09:19:44.915: E/AndroidRuntime(26483): //java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.widget.FrameLayout$LayoutParams 
04-05 09:19:44.915: E/AndroidRuntime(26483): at android.widget.FrameLayout.onMeasure(FrameLayout.java:311) 
04-05 09:19:44.915: E/AndroidRuntime(26483): at android.view.View.measure(View.java:15775) 
04-05 09:19:44.915: E/AndroidRuntime(26483): at .. 
android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1411) 
04-05 09:19:44.915: E/AndroidRuntime(26483): at android.widget.LinearLayout.measureVertical(LinearLayout.java:698) 
04-05 09:19:44.915: E/AndroidRuntime(26483): at android.widget.LinearLayout.onMeasure(LinearLayout.java:588) 
04-05 09:19:44.915: E/AndroidRuntime(26483): at android.view.View.measure(View.java:15775) 
04-05 09:19:44.915: E/AndroidRuntime(26483): at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:651)<-------- // i think the problem is DrawerLayout 
04-05 09:19:44.915: E/AndroidRuntime(26483): //at android.view.View.measure(View.java:15775) 
04-05 09:19:44.915: E/AndroidRuntime(26483): //at 

:某些屏幕

logcat的拆卸的FrameLayout main_activity.xml

<android.support.v4.widget.DrawerLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/drawer_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 



<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:weightSum="2"  
    android:orientation="vertical"  
    > 
    <LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_weight="1"  

    > 
    <FrameLayout 
     android:id="@+id/frame_container_slider" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1"  

    /> 
    </LinearLayout> 
<!-- Framelayout to display Fragments --> 
<FrameLayout 
      android:id="@+id/frame_container"   
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
    /> 

</LinearLayout> 
<!-- Listview to display slider menu --> 
<ListView 
    android:id="@+id/list_slidermenu" 
    android:layout_width="240dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:choiceMode="singleChoice" 
    android:divider="@color/list_divider" 
    android:dividerHeight="1dp"   
    android:listSelector="@drawable/list_selector" 
    android:background="@color/list_background"/> 

MainActivity.java:

if(position!=0){ 
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0,0,0); 
    // framelayout is child of linearlayout 


getSupportFragmentManager().findFragmentById(R.id.frame_container_slider).getView().setLayoutParams(lp); 
     } 
+1

他們說,日誌不給的問題的根源.. – TheLostMind

+0

檢查進口 – Raghunandan

+0

@Raghunandan什麼問題? import android.support.v4.app.ActionBarDrawerToggle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.widget.DrawerLayout; import android.widget.AdapterView; import android.widget.FrameLayout; – Abdellah

回答

0

請從婁代碼改變您的主要活動代碼。

if (position != 0) { 
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(0,0,0); 
    getSupportFragmentManager().findFragmentById(R.id.frame_container_slider) 
           .getView() 
           .setLayoutParams(lp); 
} 
+0

我已經試過這段代碼但我需要設置weigth屬性 – Abdellah

+0

我已嘗試其他解決方案,但它們之間的設置屬性直接區別xml並執行它programmaticlly:if(position!= 0){getSupportFragmentManager()。findFragmentById(R.id.frame_container_slider).getVie w()。setVisibility(View.GONE); } else getSupportFragmentManager()。findFragmentById(R.id.frame_container_slider).getVie w()。setVisibility(View.VISIBLE); \t} framelayout不顯示,但視圖區域仍然存在 – Abdellah

相關問題