如何将“旋转器”置于按钮上方

时间:2018-08-01 22:17:37

标签: android xml

有没有一种方法可以使微调器位于按钮上方? (我的按钮顶部有很多东西,当您按下按钮时,包括按钮在内的所有内容都将消失)(按钮跨越屏幕的整个宽度)现在是我下方的微调器按钮。我尝试查看其他RelativeLayout设置,但没有用。这是下面的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"
    android:background="@color/colorBackground"
    android:minHeight="170dp"
    tools:context=".create"
    tools:layout_editor_absoluteY="81dp">


    <View
        android:id="@+id/view"
        android:layout_width="320dp"
        android:layout_height="1dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="76dp"
        android:background="@color/colorText"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <Spinner
        android:id="@+id/spinner"
        android:layout_width="296dp"
        android:layout_height="49dp"
        android:layout_marginEnd="56dp"
        android:layout_marginRight="56dp"
        app:layout_constraintEnd_toEndOf="parent"
        tools:layout_editor_absoluteY="95dp" />


    <Button
        android:id="@+id/button"
        android:layout_width="330dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="312dp"
        android:background="@drawable/button_shadow"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent" />


    <View
        android:id="@+id/view2"
        android:layout_width="320dp"
        android:layout_height="1dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="28dp"
        android:background="@color/colorText"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:fontFamily="@font/droid_sans"
        android:text="@string/done_label"
        android:textColor="@color/colorText"
        android:textSize="20sp"
        app:layout_constraintBottom_toTopOf="@+id/view"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/textView4"
        app:layout_constraintTop_toBottomOf="@+id/view2"
        app:layout_constraintVertical_bias="1.0" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="128dp"
        android:layout_marginRight="128dp"
        android:layout_marginTop="8dp"
        android:fontFamily="@font/droid_sans"
        android:text="@string/aisle_label"
        android:textColor="@color/colorText"
        android:textSize="20sp"
        app:layout_constraintBottom_toTopOf="@+id/view"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/view2"
        app:layout_constraintVertical_bias="1.0" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:layout_marginEnd="44dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="44dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="5dp"
        android:fontFamily="@font/droid_sans"
        android:text="@string/qty_label"
        android:textColor="@color/colorText"
        android:textSize="20sp"
        app:layout_constraintBottom_toTopOf="@+id/view"
        app:layout_constraintEnd_toStartOf="@+id/textView4"
        app:layout_constraintHorizontal_bias="0.973"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/view2"
        app:layout_constraintVertical_bias="0.7" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:fontFamily="@font/droid_sans"
        android:text="@string/item_label"
        android:textColor="@color/colorText"
        android:textSize="20sp"
        app:layout_constraintBottom_toTopOf="@+id/view"
        app:layout_constraintEnd_toStartOf="@+id/textView3"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/view2"
        app:layout_constraintVertical_bias="1.0" />




</android.support.constraint.ConstraintLayout>

编辑:我将按钮和微调器置于框架布局中,当我在手机上对其进行测试时,它可以工作。但是我在更大尺寸(和较新的android版本)的手机上进行了测试,但旋转框没有显示(可能再次隐藏了?)不知道为什么它可以在一部手机上运行而在另一部手机上无法运行,

<FrameLayout
    android:layout_width="327dp"
    android:layout_height="63dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.195"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/view">




    <Button
        android:id="@+id/buttontest"
        android:layout_width="313dp"
        android:layout_height="63dp"
        android:layout_marginEnd="24dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="24dp"
        android:layout_marginStart="8dp"
        android:background="@drawable/button_shadow"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.863"
        app:layout_constraintStart_toStartOf="parent"
        tools:layout_editor_absoluteY="102dp" />


    <Spinner
        android:id="@+id/spinner"
        android:layout_width="249dp"
        android:layout_height="58dp"
        android:layout_marginBottom="344dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.237"
        app:layout_constraintStart_toStartOf="parent" />




</FrameLayout>

4 个答案:

答案 0 :(得分:0)

尝试致电

findViewById(R.id.spinner).bringToFront();

答案 1 :(得分:0)

您可以使用

 <?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"
    android:background="@color/browser_actions_bg_grey"
    android:minHeight="170dp"
    tools:layout_editor_absoluteY="81dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:layout_marginTop="25dp"

            >

            <TextView
                android:id="@+id/textView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Done"
                android:textSize="20sp"

                app:layout_constraintVertical_bias="1.0" />

            <TextView
                android:id="@+id/textView4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text=" aisle_label"
                android:textSize="20sp"
                app:layout_constraintBottom_toTopOf="@+id/view"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view2"
                app:layout_constraintVertical_bias="1.0" />

            <TextView
                android:id="@+id/textView3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text=" qty_label"
                android:textSize="20sp"
                app:layout_constraintBottom_toTopOf="@+id/view"
                app:layout_constraintEnd_toStartOf="@+id/textView4"
                app:layout_constraintHorizontal_bias="0.973"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view2"
                app:layout_constraintVertical_bias="0.7" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text=" item_label"
                android:textSize="20sp"
                app:layout_constraintBottom_toTopOf="@+id/view"
                app:layout_constraintEnd_toStartOf="@+id/textView3"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/view2"
                app:layout_constraintVertical_bias="1.0" />


        </LinearLayout>

        <View
            android:id="@+id/view"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_margin="10dp"
            android:background="#a4a4a4"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />


        <Spinner
            android:id="@+id/spinner"
            android:layout_width="match_parent"
            android:layout_height="49dp"
            android:layout_gravity="center"
            android:layout_margin="10dp"
            />


        <Button
            android:id="@+id/button"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="Button"
            app:layout_constraintStart_toStartOf="parent" />


        <View
            android:id="@+id/view2"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_margin="10dp"
            android:background="#a4a4a4"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />



    </LinearLayout>
</android.support.constraint.ConstraintLayout>

答案 2 :(得分:0)

我认为我设法解决了一些问题-创建了一个“ FrameLayout”,然后将微调器和按钮都放在了其中。

应该完成这项工作,除非我发现一个问题,然后再回到这里,这应该得到解决。 :)谢谢

答案 3 :(得分:0)

万一有人在想:

我将“按钮”放入FrameLayout中,然后将我想要的元素“置于”其下方(如其下方的代码中):

<FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="357dp"
        android:layout_height="58dp"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.195"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/view"
        app:layout_constraintVertical_bias="0.016">


        <Button
            android:id="@+id/buttontest"
            android:layout_width="393dp"
            android:layout_height="63dp"
            android:layout_marginEnd="24dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="24dp"
            android:layout_marginStart="8dp"
            android:background="@drawable/button_shadow"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.863"
            app:layout_constraintStart_toStartOf="parent"
            tools:layout_editor_absoluteY="102dp" />


    </FrameLayout>

    <EditText
        android:id="@+id/editText"
        android:layout_width="44dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="8dp"
        android:layout_marginEnd="184dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="184dp"
        android:layout_marginStart="8dp"
        android:ems="10"
        android:hint="qty"
        android:inputType="number"
        app:layout_constraintBottom_toBottomOf="@+id/frameLayout"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toEndOf="@+id/spinner"
        app:layout_constraintTop_toTopOf="@+id/frameLayout"
        app:layout_constraintVertical_bias="1.0" />

    <Spinner
        android:id="@+id/spinner"
        android:layout_width="85dp"
        android:layout_height="45dp"
        android:layout_marginBottom="8dp"
        android:layout_marginTop="8dp"
        app:layout_constraintBottom_toBottomOf="@+id/frameLayout"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.06"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="@+id/editText" />