Текстовые представления не отображаются горизонтально в Android

Привет В приведенном ниже коде текстовые представления не отображаются по горизонтали. У меня есть 4 textviews с именем save, off, test, reset, отображаемые по горизонтали, но не в правильном порядке. Это мой макет, где я сделал ошибку, может кто-нибудь, пожалуйста, помогите мне.

sample.xml:

   <RelativeLayout
                android:layout_width = "match_parent"
                android:layout_height = "wrap_content"
                android:background = "#1c1c1c"
                android:padding = "5dp">

                <TextView
                    android:layout_width = "wrap_content"
                    android:layout_height = "wrap_content"
                    android:text = "OFF"
                    android:id = "@id/txt_on"
                    android:layout_alignRight = "@+id/txt_reset"
                    android:textSize = "10dp"
                    android:layout_alignParentLeft = "true"
                    android:layout_marginLeft = "5dp"
                    android:background = "@drawable/button_press"
                    android:textColor = "@color/colorCool"
                    android:layout_centerInParent = "true"/>

                <TextView
                    android:layout_width = "wrap_content"
                    android:layout_height = "wrap_content"
                    android:text = "RESET"
                    android:id = "@id/txt_reset"
                    android:textSize = "10dp"
                    android:background = "@drawable/button_press"
                    android:textColor = "@color/colorCool"
                    android:layout_marginLeft = "20dp"
                    />

                <TextView
                    android:id = "@+id/txt_test"
                    android:layout_width = "wrap_content"
                    android:layout_height = "wrap_content"
                    android:layout_alignParentRight = "true"
                    android:gravity = "center"
                    android:text = "TEST"
                    android:layout_marginRight = "160dp"
                    android:layout_toLeftOf = "@+id/txt_reset"
                    android:background = "@drawable/button_press"
                    android:textColor = "@color/colorCool"
                    android:textSize = "10sp" />
                <TextView
                    android:id = "@+id/txt_save"
                    android:layout_width = "wrap_content"
                    android:layout_height = "wrap_content"
                    android:layout_alignParentRight = "true"
                    android:gravity = "center"
                    android:text = "SAVE"
                    android:layout_marginRight = "10dp"
                    android:layout_toLeftOf = "@+id/txt_on"
                    android:background = "@drawable/button_press"
                    android:textColor = "@color/colorCool"
                    android:textSize = "10sp" />
            </RelativeLayout>

использовать линейный макет с горизонтальной ориентацией

Pavneet_Singh 18.09.2018 07:12

используйте линейный макет с горизонтальной ориентацией и придайте вес текстовым представлениям.

AIK 18.09.2018 07:14
0
2
53
1
Перейти к ответу Данный вопрос помечен как решенный

Ответы 1

Ответ принят как подходящий

Попробуй это :

<LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
    android:layout_width = "match_parent"
    android:layout_height = "wrap_content"
    android:layout_marginTop = "@dimen/margin_50"
    android:orientation = "horizontal">

    <TextView
        android:layout_width = "0dp"
        android:layout_height = "wrap_content"
        android:layout_marginLeft = "@dimen/margin_10"
        android:layout_weight = "1"
        android:background = "@color/colorPrimary"
        android:text = "OFF"
        android:textColor = "@color/white"
        android:textSize = "10dp" />

    <TextView
        android:layout_width = "0dp"
        android:layout_height = "wrap_content"
        android:layout_marginLeft = "@dimen/margin_10"
        android:layout_weight = "1"
        android:background = "@color/colorPrimary"
        android:text = "RESET"
        android:textColor = "@color/white"
        android:textSize = "10dp" />

    <TextView
        android:id = "@+id/txt_test"
        android:layout_width = "0dp"
        android:layout_height = "wrap_content"
        android:layout_marginLeft = "@dimen/margin_10"
        android:layout_weight = "1"
        android:background = "@color/colorPrimary"
        android:gravity = "center"
        android:text = "TEST"
        android:textColor = "@color/white"
        android:textSize = "10sp" />

    <TextView
        android:id = "@+id/txt_save"
        android:layout_width = "0dp"
        android:layout_height = "wrap_content"
        android:layout_marginLeft = "@dimen/margin_10"
        android:layout_marginRight = "@dimen/margin_10"
        android:layout_weight = "1"
        android:background = "@color/colorPrimary"
        android:gravity = "center"
        android:text = "SAVE"
        android:textColor = "@color/white"
        android:textSize = "10sp" />

</LinearLayout>

Другие вопросы по теме