Размер TextView отличается для разных мобильных телефонов - PullRequest
1 голос
/ 11 ноября 2019

У меня 2 Textview один ниже первого. На некоторых мобильных телефонах он выглядит идеально, но на некоторых мобильных телефонах его размер изменяется, он не покрывает экран должным образом.

Ниже мой Textview один с 580dp , а другой с 30dp .

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

        <TextView
            android:id="@+id/page_data"
            android:layout_width="match_parent"
            android:layout_height="580dp"
            android:fontFamily="sans-serif-black"
            android:gravity="start|top"
            android:padding="15dp" />

        <TextView
            android:id="@+id/page_no_back"
            android:layout_width="match_parent"
            android:layout_height="30dp"
            android:layout_gravity="bottom"
            android:fontFamily="sans-serif-medium"
            android:gravity="center"
            android:padding="5dp"
            android:text="Page No" />

Ответы [ 2 ]

1 голос
/ 11 ноября 2019

Вы можете решить эту проблему, используя ConstraintLayout в качестве родительского для представления и задав constraints между представлениями для определения взаимосвязи. Проверьте приведенный ниже макет как, например.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:background="#d3d3d3"
    tools:context=".Create">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="20dp"
        app:cardCornerRadius="30dp"
        app:cardElevation="0dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView
                android:id="@+id/page_data"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:fontFamily="sans-serif-black"
                app:layout_constraintTop_toTopOf="parent"
                app:layout_constraintBottom_toTopOf="@+id/page_no_back"
                android:gravity="start|top"
                android:padding="15dp" />

            <TextView
                android:id="@+id/page_no_back"
                app:layout_constraintBottom_toBottomOf="parent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom"
                android:fontFamily="sans-serif-medium"
                android:gravity="center"
                android:padding="5dp"
                android:text="Page No" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.cardview.widget.CardView>

</RelativeLayout>
0 голосов
/ 11 ноября 2019

Я отредактировал предоставленный вами XML. Попробуйте это

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    android:orientation="vertical"
    android:layout_centerVertical="true"
    tools:context=".Create">

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_rowWeight="1"
        android:layout_columnWeight="1"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        app:cardCornerRadius="30dp"
        app:cardElevation="0dp">

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

            <TextView
                android:id="@+id/page_data"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="58"
                android:gravity="start|top"
                android:padding="15dp"
                android:textSize="18sp" />

            <TextView
                android:id="@+id/page_no_back"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="3"
                android:layout_gravity="bottom"
                android:fontFamily="sans-serif-medium"
                android:gravity="center"
                android:padding="5dp"
                android:text="Page No" />

        </LinearLayout>

    </androidx.cardview.widget.CardView>

</LinearLayout>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...