簡體   English   中英

Android Studio布局已壓縮

[英]Android Studio Layout is Compressed

我有個問題。 一切看起來都壓縮了,但是我在IDE中的設計布局仍然是正常的。 可能是什么問題呢?

第一張圖片:應用程序的輸出。 一切都被壓縮了。 我不知道發生了什么

第二張照片:一切似乎都很正常

這是我的XML代碼:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".MainActivity"
tools:showIn="@layout/activity_main">

<android.support.constraint.ConstraintLayout
    android:layout_width="395dp"
    android:layout_height="659dp"
    tools:ignore="MissingConstraints"
    tools:layout_editor_absoluteX="8dp"
    tools:layout_editor_absoluteY="8dp">

    <Button
        android:id="@+id/btn_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn_text"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="131dp" />

    <Button
        android:id="@+id/btn_txt_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableStart="@android:drawable/ic_dialog_email"
        android:text="@string/btn_txt_image"
        tools:layout_editor_absoluteX="117dp"
        tools:layout_editor_absoluteY="131dp" />

    <ImageButton
        android:id="@+id/ibtn_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="TODO"
        android:onClick="doImageButton"
        app:srcCompat="@android:drawable/ic_menu_camera"
        tools:layout_editor_absoluteX="237dp"
        tools:layout_editor_absoluteY="128dp" />

    <CheckBox
        android:id="@+id/cbx_fruit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/cbx_fruit"
        tools:layout_editor_absoluteX="34dp"
        tools:layout_editor_absoluteY="221dp" />

    <CheckBox
        android:id="@+id/cbx_meat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/cbx_meat"
        tools:layout_editor_absoluteX="135dp"
        tools:layout_editor_absoluteY="221dp" />

    <RadioGroup
        android:id="@+id/rgrp_level"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:layout_editor_absoluteX="34dp"
        tools:layout_editor_absoluteY="283dp">

        <RadioButton
            android:id="@+id/rbtn_one"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/rbtn_one" />

        <RadioButton
            android:id="@+id/rbtn_two"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/rbtn_two" />

        <RadioButton
            android:id="@+id/rbtn_three"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="@string/rbtn_three" />
    </RadioGroup>

    <RatingBar
        android:id="@+id/rbar_star"
        android:layout_width="435dp"
        android:layout_height="116dp"
        tools:layout_editor_absoluteX="-37dp"
        tools:layout_editor_absoluteY="454dp" />

    <EditText
        android:id="@+id/etxt_msg"
        android:layout_width="251dp"
        android:layout_height="55dp"
        android:ems="10"
        android:inputType="textPersonName"
        android:text="@string/etxt_msg"
        tools:layout_editor_absoluteX="16dp"
        tools:layout_editor_absoluteY="606dp" />

    <Button
        android:id="@+id/btn_toast"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn_toast"
        tools:layout_editor_absoluteX="293dp"
        tools:layout_editor_absoluteY="612dp" />

    <ToggleButton
        android:id="@+id/tbtn_power"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/tbtn_power"
        tools:layout_editor_absoluteX="279dp"
        tools:layout_editor_absoluteY="312dp" />

</android.support.constraint.ConstraintLayout>

您需要向布局視圖添加約束,這里是一個示例:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/constraintlayout_intro"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimaryDark"
    android:paddingLeft="@dimen/spacing_normal"
    android:paddingRight="@dimen/spacing_normal">

    <br.com.informant.cegonheira.ui.component.CustomViewPager
        android:id="@+id/viewpager_intro"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/btn_intro"
        android:layout_width="200dp"
        android:layout_marginTop="360dp"
        android:layout_height="@dimen/spacing_big"
        android:background="@drawable/background_rounded_green_gradient_button"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"  />

    <me.relex.circleindicator.CircleIndicator
        android:id="@+id/circle_indicator_intro"
        android:layout_width="match_parent"
        android:layout_height="@dimen/spacing_normal"
        android:layout_marginTop="460dp"
        app:ci_drawable="@drawable/ic_radio_white"
        app:ci_drawable_unselected="@drawable/ic_radio_grey"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

請在最后一個視圖中注意這一點(CircleIndicator):

app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"

這說明了視圖將在“錨定”位置,否則它們就像發生在您的視圖上一樣“浮動”。

您可以在此處了解更多信息: 使用ConstraintLayout構建響應式UI

祝賀您的第一個應用程序!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM