0

I need to create custom viewgroup that contains children which are proceeded with the attributes of the outer viewgroup for my custom.

For example,

<ConstraintLayout...>
   <CustomViewGroup...>
       <RecyclerView.../>
       <TextView.../>
       <TextView.../>
       <CustomView.../>
       <RecyclerView.../>
       <Button.../>
       <Button.../>
   </CustomViewGroup>
</ConstraintLayout>

So I need for all of these RecyclerView, TextView, TextView, CustomView, RecyclerView, Button and Button to use the attributes of ConstraintLayout like

app:layout_constraintWidth_percent
app:layout_constraintHeight_percent
app:layout_constraintTop_toBottomOf
app:layout_constraintLeft_toLeftOf
app:layout_constraintRight_toRightOf
app:layout_constraintBottom_toTopOf
etc.

And the one sense of CustomViewGroup is to be used, for example, like FrameLayout, to be the container of several fragments but without many other unnecessary extra properties (all views of these fragments should be depended only on ConstraintLayout constraints).

The main point of my own don't use the nested layouts (so that the CustomViewGroup needs to be like a fake layout).

UPDATE By virtue of Mike M. comment I need to clarify my request. I need to have some Activity with three buttons in the top and the fragments area below. Inside this fragment area three fragments should be displayed. Two fragments are almost similar and the third is different from others. First button changes the fragment area with first fragment, second button changes the fragment area with second fragment and the third button changes the fragment area with third fragment. The first and second buttons may be proceeded with one fragment just changing some parameters of general views and the third button should displays the third fragment. In any case I don't want to have nested viewgroups to arrange views inside fragments or these viewgroup's attributes should not be used by the views inside. So that I need the solutions to make these views depend on positioning attributes of the root ViewGroup ignoring the attributes of nearest viewgroups.

Sergey V.
  • 981
  • 2
  • 12
  • 24
  • This is a little unclear. Are you saying that the outermost `ViewGroup` won't always be `ConstraintLayout`? If so, how will you know which attributes to use on the inner children? Or, where are those attributes coming from, in that case? Otherwise, if you're saying it is always going to be `ConstraintLayout`, why can't `CustomViewGroup` itself be a `ConstraintLayout`? I'm not sure what you mean by fake layout, but are you sure you need a `ViewGroup` at all? Do you maybe need custom `LayoutInflater` behavior instead? Like with a `Factory`? We might need a more explicit mock-up. – Mike M. Oct 30 '22 at 00:48

0 Answers0