DrawerLayout 内部的内部视图布局总是 returns FrameLayout
Inner View Layout inside of DrawerLayout always returns FrameLayout
我在 DrawerLayout 中有 LinearLayout,它根据 layout_weight 呈现抽屉项目和视图。我试图通过将其高度设置为 0 或使用 View.Visibility - GONE[= 以编程方式隐藏该视图44=] 属性.
尝试过
By setting its Visibilty as GONE it acts as INVISIBLE
By getting its LayoutParams and setting its height to 0. Though it acts as INVISIBLE
父布局:mother.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
android:id="@+id/activityMotherDrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include layout="@layout/activity_mother" />
<include layout="@layout/motherdrawer" />
</android.support.v4.widget.DrawerLayout>
布局:motherdrawer.xml
<?xml version="1.0" encoding="utf-8"?>
<com.app.ui.view.ScrimInsetsFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerRootLayout"
android:layout_width="@dimen/activity_mother_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/background_application"
android:fitsSystemWindows="false"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/activityMotherDrawerInnerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/activity_mother_drawer_layout_padding">
<LinearLayout
android:id="@+id/activityMotherDrawerInnerInnerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/activityMotherDrawerMyAttendanceLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:clickable="true"
android:orientation="vertical">
<ImageView
android:id="@+id/activityMotherDrawerMyAttendanceIv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_centerInParent="true"
android:layout_weight="1.5"
android:padding="@dimen/activity_mother_drawer_image_padding"
android:scaleType="centerInside"
android:src="@drawable/ic_drawer_attendance" />
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@id/activityMotherDrawerMyAttendanceIv"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:gravity="top|center"
android:text="@string/activity_mother_drawer_attendance"
android:textColor="@color/colorGray"
android:textSize="@dimen/activity_mother_drawer_text_size" />
</LinearLayout>
<LinearLayout
android:id="@+id/activityMotherDrawerDashboardLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:clickable="true"
android:orientation="vertical">
<ImageView
android:id="@+id/activityMotherDrawerDashboardIv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_centerInParent="true"
android:layout_weight="1.5"
android:padding="@dimen/activity_mother_drawer_image_padding"
android:scaleType="centerInside"
android:src="@drawable/ic_drawer_dashboard" />
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@id/activityMotherDrawerDashboardIv"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:gravity="top|center"
android:text="@string/activity_mother_drawer_dashboard"
android:textColor="@color/colorGray"
android:textSize="@dimen/activity_mother_drawer_text_size" />
</LinearLayout>
<LinearLayout
android:id="@+id/activityMotherDrawerSettingsLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:clickable="true"
android:orientation="vertical">
<ImageView
android:id="@+id/activityMotherDrawerSettingsIv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_centerInParent="true"
android:layout_weight="1.5"
android:padding="@dimen/activity_mother_drawer_image_padding"
android:scaleType="centerInside"
android:src="@drawable/ic_drawer_settings" />
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@id/activityMotherDrawerSettingsIv"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:gravity="top|center"
android:text="@string/activity_mother_drawer_setting"
android:textColor="@color/colorGray"
android:textSize="@dimen/activity_mother_drawer_text_size" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</com.app.ui.view.ScrimInsetsFrameLayout>`
每当我尝试使用 getLayoutParams 获取 layoutParam 时,它 returns FrameLayout 其中它的 ParentView 是 LinearLayout.
使用Java:
mDashboardLayout = (LinearLayout)mDrawerInnerRootLayout.findViewById(R.id.activityMotherDrawerDashboardLayout);
LinearLayout.LayoutParams mParams = (LinearLayout.LayoutParams) mDashboardLayout.getLayoutParams();//returns FrameLayout instead where it should return LinearLayout
mDashboardLayout.setVisibility(View.GONE); //it acts as INVISIBILITY
Can anyone enlighten me why it returns FrameLayout instead of
LinearLayout Or Why its Visibility changes to INVISIBLE instead of GONE?
尽管更改视图 - GONE
或 INVISIBLE
的可见性仍然视图始终不可见。它确实接受 onClick 事件。根据 SO,我想完全删除该视图。我可以使用以下方法实现它。
我正在相应地以编程方式将 View 添加到 ParentView 层次结构并刷新整个布局。
View inflatedDashboardView;
inflatedDashboardView = mInflater.inflate(R.layout.layout_drawer_dashboard, mDrawerInnerRootLayout, false);
mDashboardLayout = (LinearLayout) inflatedDashboardView.findViewById(R.id.activityMotherDrawerDashboardLayout);
mDrawerInnerRootLayout.addView(inflatedDashboardView);
mDrawerInnerRootLayout.forceLayout();
我仍然无法理解为什么 DrawerLayout 内部的 InnerView 布局总是 return FrameLayout。
我在 DrawerLayout 中有 LinearLayout,它根据 layout_weight 呈现抽屉项目和视图。我试图通过将其高度设置为 0 或使用 View.Visibility - GONE[= 以编程方式隐藏该视图44=] 属性.
尝试过
By setting its Visibilty as GONE it acts as INVISIBLE
By getting its LayoutParams and setting its height to 0. Though it acts as INVISIBLE
父布局:mother.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.DrawerLayout
android:id="@+id/activityMotherDrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include layout="@layout/activity_mother" />
<include layout="@layout/motherdrawer" />
</android.support.v4.widget.DrawerLayout>
布局:motherdrawer.xml
<?xml version="1.0" encoding="utf-8"?>
<com.app.ui.view.ScrimInsetsFrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawerRootLayout"
android:layout_width="@dimen/activity_mother_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/background_application"
android:fitsSystemWindows="false"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/activityMotherDrawerInnerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/activity_mother_drawer_layout_padding">
<LinearLayout
android:id="@+id/activityMotherDrawerInnerInnerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/activityMotherDrawerMyAttendanceLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:clickable="true"
android:orientation="vertical">
<ImageView
android:id="@+id/activityMotherDrawerMyAttendanceIv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_centerInParent="true"
android:layout_weight="1.5"
android:padding="@dimen/activity_mother_drawer_image_padding"
android:scaleType="centerInside"
android:src="@drawable/ic_drawer_attendance" />
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@id/activityMotherDrawerMyAttendanceIv"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:gravity="top|center"
android:text="@string/activity_mother_drawer_attendance"
android:textColor="@color/colorGray"
android:textSize="@dimen/activity_mother_drawer_text_size" />
</LinearLayout>
<LinearLayout
android:id="@+id/activityMotherDrawerDashboardLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:clickable="true"
android:orientation="vertical">
<ImageView
android:id="@+id/activityMotherDrawerDashboardIv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_centerInParent="true"
android:layout_weight="1.5"
android:padding="@dimen/activity_mother_drawer_image_padding"
android:scaleType="centerInside"
android:src="@drawable/ic_drawer_dashboard" />
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@id/activityMotherDrawerDashboardIv"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:gravity="top|center"
android:text="@string/activity_mother_drawer_dashboard"
android:textColor="@color/colorGray"
android:textSize="@dimen/activity_mother_drawer_text_size" />
</LinearLayout>
<LinearLayout
android:id="@+id/activityMotherDrawerSettingsLayout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center"
android:layout_weight="1"
android:clickable="true"
android:orientation="vertical">
<ImageView
android:id="@+id/activityMotherDrawerSettingsIv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_centerInParent="true"
android:layout_weight="1.5"
android:padding="@dimen/activity_mother_drawer_image_padding"
android:scaleType="centerInside"
android:src="@drawable/ic_drawer_settings" />
<android.support.v7.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_below="@id/activityMotherDrawerSettingsIv"
android:layout_centerHorizontal="true"
android:layout_weight="1"
android:gravity="top|center"
android:text="@string/activity_mother_drawer_setting"
android:textColor="@color/colorGray"
android:textSize="@dimen/activity_mother_drawer_text_size" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</com.app.ui.view.ScrimInsetsFrameLayout>`
每当我尝试使用 getLayoutParams 获取 layoutParam 时,它 returns FrameLayout 其中它的 ParentView 是 LinearLayout.
使用Java:
mDashboardLayout = (LinearLayout)mDrawerInnerRootLayout.findViewById(R.id.activityMotherDrawerDashboardLayout);
LinearLayout.LayoutParams mParams = (LinearLayout.LayoutParams) mDashboardLayout.getLayoutParams();//returns FrameLayout instead where it should return LinearLayout
mDashboardLayout.setVisibility(View.GONE); //it acts as INVISIBILITY
Can anyone enlighten me why it returns FrameLayout instead of LinearLayout Or Why its Visibility changes to INVISIBLE instead of GONE?
尽管更改视图 - GONE
或 INVISIBLE
的可见性仍然视图始终不可见。它确实接受 onClick 事件。根据 SO,我想完全删除该视图。我可以使用以下方法实现它。
我正在相应地以编程方式将 View 添加到 ParentView 层次结构并刷新整个布局。
View inflatedDashboardView;
inflatedDashboardView = mInflater.inflate(R.layout.layout_drawer_dashboard, mDrawerInnerRootLayout, false);
mDashboardLayout = (LinearLayout) inflatedDashboardView.findViewById(R.id.activityMotherDrawerDashboardLayout);
mDrawerInnerRootLayout.addView(inflatedDashboardView);
mDrawerInnerRootLayout.forceLayout();
我仍然无法理解为什么 DrawerLayout 内部的 InnerView 布局总是 return FrameLayout。