英文:
Change Coordinator Layout's layout above property
问题
如何添加或删除CoordinatorLayout的属性?
例如这样?
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/tab_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/navigation"
android:fitsSystemWindows="true">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我想根据值添加或删除layout_above属性。我该怎么做?
谢谢
我尝试了放置这段代码:
CoordinatorLayout layoutCoordinator = findViewById(R.id.tab_coordinator_layout);
CoordinatorLayout.LayoutParams layoutParams;
layoutParams = (CoordinatorLayout.LayoutParams) layoutCoordinator.getLayoutParams();
layoutParams.removeRule(/* 用于布局的代码 ?? */);
但缺少了remove和add rule函数,为什么?
英文:
how can i add or remove property of coordinator layout?
Such as this?
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/tab_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/navigation"
android:fitsSystemWindows="true">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
I want add or remove the layout_above property in base of value.
How can i do it?
Thanks
I've tried to put this code:
CoordinatorLayout layoutCoordinator = findViewById(R.id.tab_coordinator_layout);
CoordinatorLayout.LayoutParams layoutParams;
layoutParams = (CoordinatorLayout.LayoutParams) layoutCoordinatot.getLayoutParams();
layoutParams.removeRule(/* code for layout ?? */);
But it is missing the remove and add rule function why?
答案1
得分: 0
缺少addRule和removeRule函数,因为这些函数不属于CoordinatorLayout.LayoutParams类,而是属于RelativeLayout.LayoutParams类。
CoordinatorLayout tabCL = findViewById(R.id.tab_coordinator_layout);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tabCL.getLayoutParams();
params.removeRule(RelativeLayout.ABOVE);
tabCL.setLayoutParams(params);
英文:
It is missing the addRule and removeRule functions because these function are not a part of class CoordinatorLayout.LayoutParams but of RelativeLayout.LayoutParams.
CoordinatorLayout tabCL = findViewById(R.id.tab_coordinator_layout);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tabCL.getLayoutParams();
params.removeRule(RelativeLayout.ABOVE);
tabCL.setLayoutParams(params);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论