Плавающая кнопка действия - проблема с отрисовкой во время разработки и выполнения - PullRequest
0 голосов
/ 10 июля 2020

Наблюдайте, работая с простым дизайном экрана входа в систему с двумя EditText и плавающей кнопкой действия.

Наблюдение: Представления отображаются некорректно; взгляните на ниже XML код макета и прикрепленное изображение, показывающее представление макета во время разработки.

ПРИМЕЧАНИЕ: Тот же пользовательский интерфейс отображается в реальном или виртуальном устройства тоже.

activity_login. xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
    tools:context=".ui.LoginActivity">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="32dp"
        android:layout_marginTop="200dip"
        android:layout_marginEnd="32dp"
        android:orientation="vertical"
        android:padding="10dip"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <EditText
            android:id="@+id/etUsername"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:drawableStart="@drawable/ic_mobile"
            android:drawablePadding="10dip"
            android:ems="10"
            android:hint="@string/username"
            android:inputType="textPersonName"
            android:textColorHint="@color/colorAccent"
            tools:ignore="Autofill" />

        <EditText
            android:id="@+id/etPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="30dip"
            android:drawableStart="@drawable/ic_key"
            android:drawablePadding="10dip"
            android:ems="10"
            android:hint="@string/password"
            android:inputType="textPassword"
            android:textColorHint="@color/colorAccent"
            tools:ignore="Autofill" />

        <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </LinearLayout>

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/screen_size"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:text="@string/forget_password"
        android:textAppearance="@style/TextAppearance.AppCompat.Medium"
        android:textColor="@android:color/white"
        android:textStyle="bold"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

style. xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>
        <item name="android:windowFullscreen">true</item>
        <item name="android:windowContentOverlay">@null</item>
    </style>

</resources>

Вот как это выглядит. введите описание изображения здесь

Другие вещи, которые могут потребоваться для большего!

  • Android Studio: 4.0
  • compileSdkVersion 30
  • buildToolsVersion "30.0. 0 "
  • minSdkVersion 21
  • argetSdkVersion 30

ниже приведен список используемых зависимостей

dependencies {
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.0'
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'androidx.cardview:cardview:1.0.0'
    implementation 'androidx.recyclerview:recyclerview:1.1.0'
    implementation 'androidx.viewpager2:viewpager2:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'com.google.android.material:material:1.1.0'
    testImplementation 'junit:junit:4.13'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    
    implementation 'com.squareup.picasso:picasso:2.71828'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
}

1 Ответ

0 голосов
/ 10 июля 2020

Проблема с плавающей кнопкой действия заключается в том, что вы не установили

android:layout_gravity="bottom|end", что требуется , чтобы установить кнопку в нижнюю позицию макета. Также добавьте android:layout_margin="value", чтобы определить его относительное положение от границ макета.

...