Совместите номера с RatingBar - Android - PullRequest
0 голосов
/ 04 ноября 2018

Я использую RatingBar в своем приложении и назначаю номера для звезд для удобства пользователя, но выравнивание этих номеров меняется при каждом изменении устройства. Несмотря на то, что я использовал разные макеты для разных экранов, но все же на некоторых мобильных устройствах форматирование не очень хорошее.

Что я хочу

enter image description here

что показывает на некоторых мобильных телефонах

enter image description here

Ответы [ 2 ]

0 голосов
/ 04 ноября 2018

Использовать макет ограничения в качестве родителя и соответствовать линейному макету. Это должно работать нормально.

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteX="38dp"
        tools:layout_editor_absoluteY="192dp" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        app:layout_constraintBottom_toTopOf="@+id/ratingBar"
        app:layout_constraintEnd_toEndOf="@+id/ratingBar"
        app:layout_constraintStart_toStartOf="@+id/ratingBar">

        <TextView
            android:id="@+id/textView7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_vertical|center_horizontal"
            android:text="1"
            android:textAlignment="center" />

        <TextView
            android:id="@+id/textView15"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_vertical|center_horizontal"
            android:text="2"
            android:textAlignment="center" />

        <TextView
            android:id="@+id/textView17"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_vertical|center_horizontal"
            android:text="3"
            android:textAlignment="center" />

        <TextView
            android:id="@+id/textView18"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_vertical|center_horizontal"
            android:text="4"
            android:textAlignment="center" />

        <TextView
            android:id="@+id/textView19"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center_vertical|center_horizontal"
            android:text="5"
            android:textAlignment="center" />
    </LinearLayout>
</android.support.constraint.ConstraintLayout>

enter image description here

0 голосов
/ 04 ноября 2018

Используйте приведенный ниже тип динамически изменяемого макета. Я добавил пример ниже. Вы можете добавить свои элементы для соответствующих столбцов. Это будет меняться в зависимости от устройства

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/tempo_activity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:weightSum="2">

             <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:layout_weight="1">

                    <!-- first row -->

                      <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="horizontal"
                        android:weightSum="7">

                          <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:orientation="horizontal"
                            android:layout_weight="5">

                             <!-- first column (name) -->

                           </LinearLayout>

                          <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:orientation="horizontal"
                            android:layout_weight="2"
                            android:weightSum="5">

                             <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:orientation="horizontal"
                                android:layout_weight="4">

                                 <!-- second column (name) -->

                             </LinearLayout>

                              <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:orientation="horizontal"
                                android:layout_weight="1"
                                android:weightSum="4">


                                  <LinearLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:orientation="horizontal"
                                    android:layout_weight="3">

                                     <!-- third column (name) -->

                                 </LinearLayout>

                                 <LinearLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:orientation="horizontal"
                                    android:layout_weight="1"
                                    android:weightSum="3">

                                       <LinearLayout
                                            android:layout_width="match_parent"
                                            android:layout_height="match_parent"
                                            android:orientation="horizontal"
                                            android:layout_weight="2">

                                             <!-- fourth column (name) -->

                                       </LinearLayout>

                                        <LinearLayout
                                            android:layout_width="match_parent"
                                            android:layout_height="match_parent"
                                            android:orientation="horizontal"
                                            android:layout_weight="1"
                                            android:weightSum="2">

                                                   <LinearLayout
                                                        android:layout_width="match_parent"
                                                        android:layout_height="match_parent"
                                                        android:orientation="horizontal"
                                                        android:layout_weight="1">

                                                         <!-- fifth column (name) -->

                                                   </LinearLayout>
                                                    <LinearLayout
                                                        android:layout_width="match_parent"
                                                        android:layout_height="match_parent"
                                                        android:orientation="horizontal"
                                                        android:layout_weight="1">

                                                         <!-- sixth column (name) -->

                                                   </LinearLayout>


                                       </LinearLayout>



                                 </LinearLayout>


                             </LinearLayout>


                           </LinearLayout>

                     </LinearLayout>


             </LinearLayout>

             <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    android:layout_weight="1">

                    <!-- second row -->

                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="horizontal"
                        android:weightSum="7">

                          <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:orientation="horizontal"
                            android:layout_weight="5">

                             <!-- first column (name) -->

                           </LinearLayout>

                          <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:orientation="horizontal"
                            android:layout_weight="2"
                            android:weightSum="5">

                             <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:orientation="horizontal"
                                android:layout_weight="4">

                                 <!-- second column (name) -->

                             </LinearLayout>

                              <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="match_parent"
                                android:orientation="horizontal"
                                android:layout_weight="1"
                                android:weightSum="4">


                                  <LinearLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:orientation="horizontal"
                                    android:layout_weight="3">

                                     <!-- third column (name) -->

                                 </LinearLayout>

                                 <LinearLayout
                                    android:layout_width="match_parent"
                                    android:layout_height="match_parent"
                                    android:orientation="horizontal"
                                    android:layout_weight="1"
                                    android:weightSum="3">

                                       <LinearLayout
                                            android:layout_width="match_parent"
                                            android:layout_height="match_parent"
                                            android:orientation="horizontal"
                                            android:layout_weight="2">

                                             <!-- fourth column (name) -->

                                       </LinearLayout>

                                        <LinearLayout
                                            android:layout_width="match_parent"
                                            android:layout_height="match_parent"
                                            android:orientation="horizontal"
                                            android:layout_weight="1"
                                            android:weightSum="2">

                                                   <LinearLayout
                                                        android:layout_width="match_parent"
                                                        android:layout_height="match_parent"
                                                        android:orientation="horizontal"
                                                        android:layout_weight="1">

                                                         <!-- fifth column (name) -->

                                                   </LinearLayout>
                                                    <LinearLayout
                                                        android:layout_width="match_parent"
                                                        android:layout_height="match_parent"
                                                        android:orientation="horizontal"
                                                        android:layout_weight="1">

                                                         <!-- sixth column (name) -->

                                                   </LinearLayout>


                                       </LinearLayout>



                                 </LinearLayout>


                             </LinearLayout>


                           </LinearLayout>

                     </LinearLayout>

             </LinearLayout>




   </LinearLayout>

</LinearLayout>
...