0

I have card scroll view and I am trying to get the content in my cards to display centered.

I tried:

LinearLayout.LayoutParams para=new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT );
       para.gravity = Gravity.CENTER;

        csvCardsView.setLayoutParams(para);
        setContentView(csvCardsView);

I also tried using a layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/options_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

<com.google.android.glass.widget.CardScrollView
        android:id="@+id/options_csv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center">

</com.google.android.glass.widget.CardScrollView>

</LinearLayout>

and setting the content to this setContentView(R.layout.options_view);

None of the above have any effect on the placement of the text (always top left).

my CardScrollView contains a List<Card>

UPDATE: I couldn't get the scroll view to work using the layouts above and creating cards programatically doesn't give me an option to configure the text within the card.

Card optionCard = new Card(this);
        optionCard.setText(optionNames.get(currentOptionIndex) + " : "+ option.getDisplayName());
        mlcCards.add(optionCard);

where mlcCards is an ArrayList<Card>, I also tried setting this in my ScrollViewAdapter but this didn't seem to work either.

@Override
public View getView(int position, View convertView, ViewGroup parent)
{
    LinearLayout.LayoutParams para=new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT );
    para.gravity = Gravity.CENTER;
    View view = mlcCards.get(position).toView();
    view.setLayoutParams(para);
    return view;
}
Alex Edwards
  • 1,613
  • 3
  • 24
  • 48

1 Answers1

1

You're best off adding full-width, full-height (i.e. match_parent) Cards that themselves center their content.

straya
  • 5,002
  • 1
  • 28
  • 35
  • Yes after reading the docs again I noticed this https://developers.google.com/glass/develop/gdk/reference/com/google/android/glass/widget/CardScrollAdapter#getView%28int,%20android.view.View,%20android.view.ViewGroup%29 specifies that i should be calling setItemOnCard, so I am trying to build a layout which will mean that a view is passed to that method (i hope) – Alex Edwards Mar 07 '14 at 17:37
  • I updated my answer with some more details if you have any further suggestions? – Alex Edwards Mar 10 '14 at 16:32
  • I don't use Cards myself, so can't speak from experience. If there is a bug or limitation in this regard, I avoid it by using custom layouts. If you inflate a custom layout in getView you'll have much more control of the view. – straya Mar 10 '14 at 17:46
  • also if you feel there is a bug/limitation then lodge a new bug/enhancement request via https://code.google.com/p/google-glass-api/issues/list – straya Mar 10 '14 at 17:48
  • Thanks, I just used a `TextView` and everything worked great!! So I guess the `Card` lack of layout options was the problem. – Alex Edwards Mar 10 '14 at 18:59