Элементы просмотра не отображаются правильно на маленьких экранах - PullRequest
1 голос
/ 04 апреля 2020
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".LearningFragment">
    <FrameLayout
            android:id="@+id/main_fragments_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/toolbar_top"
            android:layout_above="@+id/bottom_navigation" >
        <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center">
            <TextView
                    android:id="@+id/countLearningWord"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Осталось 0 слов"
                    android:layout_weight="1"
                    android:textSize="18sp"/>
            <com.makeramen.roundedimageview.RoundedImageView
                    android:id="@+id/imageView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="12dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginRight="8dp"
                    android:layout_weight="6"
                    android:scaleType="fitStart"
                    tools:scaleType="fitXY" />
            <TextView
                    android:id="@+id/textEnglish"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:singleLine="true"
                    android:text="@string/english"
                    android:textAllCaps="true"
                    android:textSize="24sp"
                    android:textStyle="bold"/>
            <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="2"
                    android:orientation="vertical">
                <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:layout_weight="1">
                    <Button
                            android:id="@+id/button1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="Button"/>
                    <Button
                            android:id="@+id/button2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="Button"/>
                    <Button
                            android:id="@+id/button3"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="Button"/>
                </LinearLayout>
                <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:layout_weight="1">
                    <Button
                            android:id="@+id/button4"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="Button" />
                    <Button
                            android:id="@+id/button5"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="Button"/>
                    <Button
                            android:id="@+id/button6"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="Button"/>
                </LinearLayout>
            </LinearLayout>
        </LinearLayout>
    </FrameLayout>  
</FrameLayout>

введите описание изображения здесь

Я не совсем понимаю, как сделать адаптивный дизайн, но они используют dp во всех источниках, но Google говорит, что не рекомендуется используйте его, здесь я использовал LinerLayout с его замечательным android: layout_weight, но он также не работает правильно, что мне делать?

Я прочитал рекомендацию из других источников, но это не дало правильный результат: https://developer.android.com/training/multiscreen/screensizes.html

1 Ответ

0 голосов
/ 04 апреля 2020

Что вам нужно, так это ScrollView, в случаях, когда вам нужно перечислить ваши представления по вертикали, вы должны принять во внимание, что эти представления не всегда могут соответствовать размерам изображения, которым вы поделились. Так что просто используйте этот код ниже

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".LearningFragment">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">

        <FrameLayout
            android:id="@+id/main_fragments_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@+id/bottom_navigation"
            android:layout_below="@+id/toolbar_top">


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

                <TextView
                    android:id="@+id/countLearningWord"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Осталось 0 слов"
                    android:textSize="18sp" />

                <com.makeramen.roundedimageview.RoundedImageView
                    android:id="@+id/imageView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="8dp"
                    android:layout_marginLeft="8dp"
                    android:layout_marginTop="12dp"
                    android:layout_marginEnd="8dp"
                    android:layout_marginRight="8dp"
                    android:layout_weight="6"
                    android:scaleType="fitStart"
                    tools:scaleType="fitXY" />

                <TextView
                    android:id="@+id/textEnglish"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:singleLine="true"
                    android:text="@string/english"
                    android:textAllCaps="true"
                    android:textSize="24sp"
                    android:textStyle="bold" />

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

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

                        <Button
                            android:id="@+id/button1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="Button" />

                        <Button
                            android:id="@+id/button2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="Button" />

                        <Button
                            android:id="@+id/button3"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="Button" />
                    </LinearLayout>

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

                        <Button
                            android:id="@+id/button4"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="Button" />

                        <Button
                            android:id="@+id/button5"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="Button" />

                        <Button
                            android:id="@+id/button6"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:text="Button" />
                    </LinearLayout>
                </LinearLayout>
            </LinearLayout>

        </FrameLayout>
    </ScrollView>
</FrameLayout>
...