首页 > 解决方案 > 我不知道如何使用边距在布局中移动仪表

问题描述

我在应用程序中有仪表,我想将它移动到页面的中心。但是如果我做任何事情,就不会发生任何变化

<?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:id="@+id/layout_noise"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg_sc">


    <com.github.anastr.speedviewlib.TubeSpeedometer
        android:id="@+id/gauge"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginLeft="600dp"
        />

    <TextView
        android:id="@+id/tv_noise"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginTop="500dp"
        android:fontFamily="serif"
        android:text="Odmeraj amotsferu"
        android:textSize="36sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

您可以在应用程序中看到它:

在此处输入图像描述

谢谢!

标签: android

解决方案


您应该使用@Harin Kaklotar.

改变

<com.github.anastr.speedviewlib.TubeSpeedometer
    android:id="@+id/gauge"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_marginLeft="600dp"
    />

<com.github.anastr.speedviewlib.TubeSpeedometer
    android:id="@+id/gauge"
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_marginLeft="600dp"

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

您已经在tv_noise. 所以我建议你先阅读ConstraintLayoutHow to Build a Responsive UI with ConstraintLayout


推荐阅读