更改协调布局的”layout above”属性。

huangapple go评论92阅读模式
英文:

Change Coordinator Layout's layout above property

问题

如何添加或删除CoordinatorLayout的属性?
例如这样?

  1. <androidx.coordinatorlayout.widget.CoordinatorLayout
  2. android:id="@+id/tab_coordinator_layout"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:layout_above="@+id/navigation"
  6. android:fitsSystemWindows="true">
  7. <FrameLayout
  8. android:id="@+id/content_frame"
  9. android:layout_width="match_parent"
  10. android:layout_height="match_parent"
  11. android:background="@color/white"/>
  12. </androidx.coordinatorlayout.widget.CoordinatorLayout>

我想根据值添加或删除layout_above属性。我该怎么做?
谢谢

我尝试了放置这段代码:

  1. CoordinatorLayout layoutCoordinator = findViewById(R.id.tab_coordinator_layout);
  2. CoordinatorLayout.LayoutParams layoutParams;
  3. layoutParams = (CoordinatorLayout.LayoutParams) layoutCoordinator.getLayoutParams();
  4. layoutParams.removeRule(/* 用于布局的代码 ?? */);

但缺少了remove和add rule函数,为什么?

英文:

how can i add or remove property of coordinator layout?
Such as this?

  1. <androidx.coordinatorlayout.widget.CoordinatorLayout
  2. android:id="@+id/tab_coordinator_layout"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:layout_above="@+id/navigation"
  6. android:fitsSystemWindows="true">
  7. <FrameLayout
  8. android:id="@+id/content_frame"
  9. android:layout_width="match_parent"
  10. android:layout_height="match_parent"
  11. android:background="@color/white"/>
  12. </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:

  1. CoordinatorLayout layoutCoordinator = findViewById(R.id.tab_coordinator_layout);
  2. CoordinatorLayout.LayoutParams layoutParams;
  3. layoutParams = (CoordinatorLayout.LayoutParams) layoutCoordinatot.getLayoutParams();
  4. layoutParams.removeRule(/* code for layout ?? */);

But it is missing the remove and add rule function why?

答案1

得分: 0

缺少addRule和removeRule函数,因为这些函数不属于CoordinatorLayout.LayoutParams类,而是属于RelativeLayout.LayoutParams类。

  1. CoordinatorLayout tabCL = findViewById(R.id.tab_coordinator_layout);
  2. RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tabCL.getLayoutParams();
  3. params.removeRule(RelativeLayout.ABOVE);
  4. 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.

  1. CoordinatorLayout tabCL = findViewById(R.id.tab_coordinator_layout);
  2. RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) tabCL.getLayoutParams();
  3. params.removeRule(RelativeLayout.ABOVE);
  4. tabCL.setLayoutParams(params);

huangapple
  • 本文由 发表于 2023年6月19日 13:51:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76503918.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定