それはカードビューに拘束されたときに、ページのオフに行くからの眺めを修正する方法

OPWagg:

私は最近、androidxにアンドロイドプロジェクトの上に変換していると私は、ビューがページのオフに行く停止しようとして問題が生じています。次のように私のレイアウトは、カードビューとテキストビューが含まれていること、制約レイアウトです。このカードビューの中で私は、テキストビューが含まれている制約レイアウトを持っています。カードビューの私の外には、カードビューに拘束されたボタンがあります。

これで問題は私がプログラムを実行するときにカードビューが画面の消灯し、ボタンはすべて、彼らがすべて適切に拘束されているにもかかわらず、トップへの道を移動していることです。

私はこれを達成するために使用していたコードとエミュレータ上の私の結果の画像の下に表示されます。

ここでは、エディタでのレイアウトがある[1]:https://imgur.com/a/0FLa1IK

ここでエミュレータ[2]に示すレイアウトである。https://imgur.com/a/SsvKiOG

任意の助けいただければ幸いです。

<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">

    <androidx.cardview.widget.CardView
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:layout_marginBottom="8dp"
        app:layout_constraintBottom_toTopOf="@+id/materialButton"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

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

            <TextView
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginBottom="16dp"
                android:text="Text View Test"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.cardview.widget.CardView>

    <Button
        android:id="@+id/materialButton"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginBottom="256dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

タミールアブトブル:

あなたのレイアウトがあるため、この行のプッシュなっています。

android:layout_marginBottom="256dp"

別の携帯電話は、異なる画面サイズを持って、あなたのレイアウトで、あなたのビュー(「256dp」)に固定されたサイズを使用していて、それはあなたのレイアウト非応答になります。

だから、本当の電話で同じに見えないかもしれない、あなたのプレビューに良いように見えるかもしれないもの。

あなたは、画面上のいくつかのビューの任意の場所を配置し、応答それを維持したい場合は私が使用することをお勧めガイドラインを、このような何かを:

<androidx.constraintlayout.widget.ConstraintLayout 
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<androidx.cardview.widget.CardView
    android:id="@+id/cv_text"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_margin="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginBottom="8dp"
    app:layout_constraintBottom_toTopOf="@+id/materialButton"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Text View Test"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.cardview.widget.CardView>

<Button
    android:id="@+id/materialButton"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginBottom="8dp"
    app:layout_constraintBottom_toTopOf="@+id/guideline13"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent" />

<androidx.constraintlayout.widget.Guideline
    android:id="@+id/guideline13"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    app:layout_constraintGuide_percent=".5" />

</androidx.constraintlayout.widget.ConstraintLayout>

そして、それは次のようになります。

ここでは、画像の説明を入力します。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=175822&siteId=1