Как изменить размер прокрутки, чтобы все отображалось на экране? - PullRequest
0 голосов
/ 11 декабря 2018

Я не совсем уверен, что я делаю здесь неправильно.

Я бы хотел, чтобы объявление было внизу, чтобы оно отображалось на экране, и я хотел бы уменьшить scrollview или верхнего уровня linearlayout, чтобы все могло поместиться на экране.

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

    <LinearLayout

            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_alignParentBottom="true"
            >
        <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/notice"
                android:text="@string/notice"
                android:textColor="@color/colorPrimary"
                android:textSize="18sp"/>
        <ScrollView
                android:id="@+id/magic_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginEnd="8dp"
                android:layout_marginRight="8dp"
                android:layout_marginLeft="8dp"
                android:layout_marginStart="8dp"
                app:layout_constraintTop_toBottomOf="@id/notice"
                app:layout_constraintBottom_toTopOf="@id/adView">
            <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    app:layout_constraintTop_toTopOf="parent"
                    app:layout_constraintBottom_toBottomOf="parent">
                <TextView
                        android:id="@+id/text_uri_message"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:textSize="18sp"
                        android:textStyle="bold"
                        android:text="@string/test_value"
                        app:layout_constraintTop_toTopOf="parent"
                        app:layout_constraintBottom_toTopOf="@id/tags_box"/>
                <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/tags_box"
                        app:layout_constraintTop_toBottomOf="@id/text_uri_message"
                        app:layout_constraintBottom_toBottomOf="parent"/>
            </LinearLayout>
        </ScrollView>
        <com.google.android.gms.ads.AdView
                xmlns:ads="http://schemas.android.com/apk/res-auto"
                android:id="@+id/adView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                ads:adSize="SMART_BANNER"
                ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
                app:layout_constraintBottom_toBottomOf="parent">
        </com.google.android.gms.ads.AdView>

    </LinearLayout>

</android.support.constraint.ConstraintLayout>

Это работало до того, как я добавил AdView, но я не совсем уверен, где я все испортил.

В этом случае @string/test_value - это просто длинный фиктивный текст, чтобы заставить scrollview быть большим:

    Ads are an effective and easy way to earn revenue from your apps. Google AdMob is
    a smart monetization platform for apps that helps you to maximize revenue from ads and in-app purchases. More
    than 1 million apps use Google AdMob to generate a reliable revenue stream, with more than $1 billion paid to
    developers. All you need to do is sign up for Google AdMob, and then use the Google Mobile Ads SDK to place ads
    in your app with just a few lines of code. You get paid quickly in your local currency (where available), with
    no wire fees charged by Google AdMob. Also, Google AdMob’s integration with Google Play services pushes
    automatic performance improvements to Android apps without additional SDK changes.Well-placed, well-targeted ads
    in apps, particularly free apps, can achieve good click-through rates while preserving the app’s user
    experience. It’s easy to add the code to deliver ads, and Google AdMob takes care of the rest: finding and
    delivering relevant ads to your app from any of Google’s advertiser demand across Google AdMob, Google Ads, and
    the Authorized buyers. This range of advertising sources—coupled with free, industry-leading mediation—achieves
    high CPMs and excellent fill rates, automatically helping to improve your earnings.

Не должен ли wrap_content изменять размер scrollview или сделалЯ где-то ошибаюсь в макете?

Ответы [ 2 ]

0 голосов
/ 11 декабря 2018

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

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".DisplayMagic">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/notice"
            android:text="@string/notice"
            android:textColor="@color/colorPrimary"
            android:textSize="18sp"/>

        <ScrollView
            android:id="@+id/magic_container"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_marginEnd="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical" >
                <TextView
                    android:id="@+id/text_uri_message"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="18sp"
                    android:textStyle="bold"
                    android:text="@string/test_value"/>
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/tags_box" />
            </LinearLayout>
        </ScrollView>
        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:adSize="SMART_BANNER"
            app:adUnitId="ca-app-pub-3940256099942544/6300978111" >
        </com.google.android.gms.ads.AdView>

</LinearLayout>

. Это дает уведомление вверху и объявление нанижняя часть с остальной частью области для просмотра прокрутки.

0 голосов
/ 11 декабря 2018

Вы можете попробовать этот код cml: я использую макет ограничения с представлением прокрутки и adview с ограничением соответствия атрибутов, которое позволяет scrollview устанавливать себя самостоятельно с учетом связанных ограничений.

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

<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/notice"
        android:text="@string/notice"
        android:textColor="@color/colorPrimary"
        android:textSize="18sp" app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent" 
app:layout_constraintTop_toTopOf="parent"/>
<ScrollView
        android:id="@+id/magic_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintBottom_toTopOf="@id/adView"
        android:layout_marginTop="8dp" 
app:layout_constraintTop_toBottomOf="@+id/notice"
        app:layout_constraintStart_toStartOf="parent" 
app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintVertical_bias="0.0" 
app:layout_constraintHorizontal_bias="0.0">

    <android.support.constraint.ConstraintLayout android:layout_width="match_parent"

android:layout_height="wrap_content">
        <TextView
                android:id="@+id/text_uri_message"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:textSize="18sp"
                android:textStyle="bold"
                android:text="@string/gen_text"
                android:layout_marginEnd="8dp" 
app:layout_constraintEnd_toEndOf="parent"
                android:layout_marginStart="8dp" 
app:layout_constraintStart_toStartOf="@+id/tags_box"
                app:layout_constraintTop_toTopOf="parent"/>
        <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/tags_box"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent" android:layout_marginTop="8dp"
                app:layout_constraintTop_toBottomOf="@+id/text_uri_message"
                app:layout_constraintBottom_toBottomOf="parent" android:layout_marginBottom="8dp"
                app:layout_constraintHorizontal_bias="0.0" app:layout_constraintVertical_bias="1.0"/>
    </android.support.constraint.ConstraintLayout>
</ScrollView>
<com.google.android.gms.ads.AdView
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:id="@+id/adView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        ads:adSize="SMART_BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111"
        app:layout_constraintBottom_toBottomOf="parent" 
ads:layout_constraintStart_toStartOf="parent"
        ads:layout_constraintEnd_toEndOf="parent">
</com.google.android.gms.ads.AdView>
</android.support.constraint.ConstraintLayout>
...