0

I have an existing <include layout and need to change two parameters of this layout programmatically to set it in a TableLayout one time have to perform:

 android:layout_height="0dp"
 app:layout_constraintBottom_toBottomOf="parent"

and another time

 android:layout_height="wrap_content"

this is the layout

<include
    android:id="@+id/search_results_cv"
    layout="@layout/addresses_card_view"
    android:layout_width="0dp"// or wrap
    android:layout_margin="8dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@id/my_location_cv"
    app:layout_constraintBottom_toBottomOf="parent"//one time want t call another time not
/>

I do not need a ViewStub as here, because do not need to change the layout indicated in include, but the parameters inside include!

EDIT:

and this is the new include layout:

    <include
        android:id="@+id/search_results_cv"
        layout="@layout/addresses_card_view"

        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/my_location_cv"
 />
Drocchio
  • 383
  • 4
  • 21
  • I do not need to change the dimensions, how can I change layout height to wrap_content in dimens? – Drocchio Nov 20 '18 at 15:24
  • [This answer](https://stackoverflow.com/a/53344196) should be of some help. In your case, after getting the `ConstraintLayout.LayoutParams`, you would set `lp.bottomToBottom` to the ID of whichever `View` is the new constraint. To wrap the height, you set `lp.height` to `LayoutParams.WRAP_CONTENT`. After you set your values, set the `LayoutParams` back on the `View` with `setLayoutParams(lp)`. – Mike M. Nov 20 '18 at 16:08
  • please see my edit Mike, does not work for some reasons I cannot debug – Drocchio Nov 20 '18 at 16:18
  • Sorry, but I don't understand what you're saying. – Mike M. Nov 20 '18 at 16:21
  • I mean I changed the original post on the basis of your suggestion, and I showed you what I did – Drocchio Nov 20 '18 at 16:22
  • What were you saying about dpi? And how exactly does it not work? – Mike M. Nov 20 '18 at 16:22
  • was a typo, I meant "for" instead of "dpi", sorry I am on that since 10 hours – Drocchio Nov 20 '18 at 16:25
  • Also, why are you constraining the bottom of `search_results_cv` to its own bottom? That doesn't really make sense. – Mike M. Nov 20 '18 at 16:25
  • I am not good to use Kotlinx, I thought that is the way to call the – Drocchio Nov 20 '18 at 16:26
  • Nah, the `` is fine. I mean this: `params.bottomToBottom=search_results_cv.bottom`. That needs to be set to a `View` ID, not a dimension or location. – Mike M. Nov 20 '18 at 16:29
  • do not get, I am asking get bottom so to emulate `layout_bottomToBottom' = parent – Drocchio Nov 20 '18 at 16:39
  • The `layout_bottomToBottom` attribute means "align my bottom to this other `View`'s bottom". You need to give it the ID of the `View` whose bottom you want the `include`'s bottom to align with; e.g., `R.id.otherView`. – Mike M. Nov 20 '18 at 16:42
  • Oh, sorry, I might've misread that. If you mean you specifically want to set that to `parent` programmatically, then you could either use the `ConstraintLayout`'s `R.id` directly, or use `ConstraintLayout.LayoutParams.PARENT_ID`. That is, `params.bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID`. – Mike M. Nov 20 '18 at 16:49
  • you know a lot of things I cannot test now, that I am without VPN, but gotta wait tomorrow morning, I think also that I have to pass as `val params` instead of the `include id` the id global of `ConstraintLayout`, I edited the question again – Drocchio Nov 20 '18 at 17:05
  • You still haven't said exactly how it's not working. Does the `View` not go where it's supposed to? Is it the wrong dimensions? Does it just disappear? Does it crash? Does your computer catch fire? – Mike M. Nov 20 '18 at 17:08
  • ah ah, my brain catches fire, basically i tested before the views with the respective attributes and they were working, now I cannot test them because do not have access to the VPN, tomorrow morning at 8 Amsterdam time I will know. Thank you. I gave you three upvotes to some some post of you I liked. ( not that you need reputation:)) – Drocchio Nov 20 '18 at 17:45
  • Well, let's hope it works. :-) Also, I really do appreciate the gesture, but please don't upvote unless you've used an answer, and it has helped you. Upvoting several in quick succession like that is called "serial voting", and it's rather frowned upon here. It might even be reversed anyway, since there's a script on the servers that looks for that. Again, though, I do appreciate the gesture. Good luck with this. Cheers! – Mike M. Nov 20 '18 at 17:55
  • I suspected that, but you helped me other times, and if I grew before to find a job is because of people in SO as you. I will not do serial vote anymore:) Point taken – Drocchio Nov 20 '18 at 21:53
  • 1
    worked perfect, thank you Mike – Drocchio Nov 21 '18 at 12:11

0 Answers0