سؤال

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;
}
هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top