目标:从某个屏幕删除framelayout
Logcat:
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
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);
}
答案 0 :(得分:0)
请从下面的代码中更改您的主要活动代码。
if (position != 0) {
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(0,0,0);
getSupportFragmentManager().findFragmentById(R.id.frame_container_slider)
.getView()
.setLayoutParams(lp);
}