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

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

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);

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:

确定