Instead of creating a new CardBuilder with en Enum like CardBuilder.Layout.COLUMNS_FIXED, I'd like to create them with custom layouts. Is this possible? What other alternative is there?
Asked
Active
Viewed 894 times
0
-
1The reason for using `CardBuilder` is to avoid having to design your own layouts because it builds a correctly styled layout automatically by plugging in the data you give it. Why do you want to use `CardBuilder` if you also want to use your own layouts? – Tony Allevato Sep 24 '14 at 21:46
-
I am a noob. I got the CardBuilder working great, but it crops pictures to fill in the card in the CAPTION Layout. I was hoping I could make layouts and just drop them into the CardBuilder real nice and easy peasy. – RichardJohnn Sep 25 '14 at 13:08
-
So then are you supposed to create your own `CardBuilder.Layout`? I don't feel the Glass documentation is clear on how to implement an XML layout in `CardScrollView`... any thoughts? I'm lost on this. – cereallarceny Oct 09 '14 at 17:07
-
@cereallarceny, I guess CardBuilder.Layout is just an enum, so you end up making your own .xml and a LayoutInflator to create it, grab it's view and feed that to the CardScrollAdapter's getView \@Override. – RichardJohnn Oct 11 '14 at 17:22
2 Answers
3
Actually you CAN embed into a CardBuilder!
View view = new CardBuilder(context, CardBuilder.Layout.EMBED_INSIDE)
.setEmbeddedLayout(R.layout.food_table)
.setFootnote("Foods you tracked")
.setTimestamp("today")
.getView();
TextView textView1 = (TextView) view.findViewById(R.id.text_view_1);
textView1.setText("Water");
This is the correct answer, people should know it is possible.

msj121
- 2,812
- 3
- 28
- 55
-
Thank you. If I find the time to verify this, I could change answers. The lack of up votes around here, however, doesn't encourage its prioritization. – RichardJohnn Dec 10 '14 at 18:24
-
-
-
my IDE says CardBuilder cannot be cast to View. Nevertheless its possible to embed a layout like this (I tested it). – Anthea Dec 04 '15 at 09:53
-
CardBuilder has a function called "getView()". Although people don't usually chain functions in Java, I tend to use builders that way as I did in my own code above. Sorry for the confusion. The above code does work, and does give back a view. – msj121 Dec 08 '15 at 02:35
0
No, current version of CardBuilder doesn't support a custom layout. But there is plenty of examples on how to use custom layouts with a CardScrollAdapter inside a CardScrollView

fmmanrique
- 26
- 2