как выровнять чипы андроида до конца в чипгруппе? - PullRequest
0 голосов
/ 16 мая 2019

Привет, у меня есть чип-группа, и я динамически создаю чипы и добавляю в чип-группу.

Однако Я хочу, чтобы чипы находились с правой стороны чип-группы, но всегда слева, как показано здесь.

enter image description here

Я хочу, чтобы фишки Text: 0 и Text: 1 находились в самом правом конце.

Это мой код:

 <RelativeLayout
     ....
         >

    <TextView

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextTitle"
        android:layout_alignBaseline="@id/chipGroup"
        android:gravity="end|bottom"
        android:layout_marginTop="16dp"
        android:layout_below="@id/toptv"
        android:textColor="@android:color/white"
        android:textStyle="bold"
        android:textSize="14sp"
        android:id="@+id/tt1"
        />

    <com.google.android.material.chip.ChipGroup
        android:id="@+id/chipGroup"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_toRightOf="@id/tt1"
        android:layout_below="@id/toptv"
        android:textColor="@android:color/black"
        android:textStyle="bold"
        android:textSize="12sp"
        />
     </RelativeLayout>

Вот как я динамически добавляю фишки к группе фишек:

    Chip chip;

    for(int i=0;i<2;i++){
        chip = new Chip(this);
        chip.setText("Text:"+i);
        chip.setChipBackgroundColorResource(android.R.color.darker_gray);
        chip.setTextColor(Color.WHITE);
        mChipGroup.addView(chip);
    }

Я искал некоторые сообщения SOF, но не смог выровнять фишки по правому краю. Любая помощь будет очень полезна.

Ответы [ 2 ]

0 голосов
/ 21 мая 2019

Просто замените его

 <RelativeLayout
 ....
     >

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="TextTitle"
    android:layout_alignBaseline="@+id/chipGroup"
    android:layout_toLeftOf="@+id/chipGroup"
    android:gravity="end|bottom"
    android:layout_marginTop="16dp"
    android:layout_below="@+id/toptv"
    android:textColor="@android:color/white"
    android:textStyle="bold"
    android:textSize="14sp"
    android:id="@+id/tt1"
    />

<com.google.android.material.chip.ChipGroup
    android:id="@+id/chipGroup"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_below="@+id/toptv"
    android:textColor="@android:color/black"
    android:textStyle="bold"
    android:textSize="12sp"
    />
 </RelativeLayout>
0 голосов
/ 17 мая 2019

Вам необходимо изменить ChipGroup групповое свойство.здесь изменен код.

<RelativeLayout
 ....
     >

<TextView

    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextTitle"
    android:layout_alignBaseline="@id/chipGroup"
    android:gravity="end|bottom"
    android:layout_marginTop="16dp"
    android:layout_below="@id/toptv"
    android:textColor="@android:color/white"
    android:textStyle="bold"
    android:textSize="14sp"
    android:id="@+id/tt1"
    />

<com.google.android.material.chip.ChipGroup
    android:id="@+id/chipGroup"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_toRightOf="@id/tt1"
    android:layout_below="@id/toptv"
    android:textColor="@android:color/black"
    android:textStyle="bold"
    android:gravity="end"
    android:textSize="12sp"
    />
 </RelativeLayout>

Надеюсь, это сработает.если нет, то оставьте свой RelativeLayout на свой вопрос.

...