【问题标题】:Android - Put object each others on Relative Layout [duplicate]Android - 将对象彼此放在相对布局上[重复]
【发布时间】:2018-08-31 11:57:49
【问题描述】:

我需要在RelativeLayout中的Button顶部放置一个TextView,所以我将TextView放在Button之前,但它不起作用

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <TextView
                android:id="@+id/textView"
                android:layout_width="20pt"
                android:layout_height="22pt"
                android:layout_gravity="start"
                android:layout_marginTop="4pt"
                android:background="@drawable/rounded_numbers"
                android:gravity="center"
                android:text="1" />
        <Button
                android:id="@+id/peso_but"
                android:layout_width="100pt"
                android:layout_height="20pt"
                android:layout_marginStart="17pt"
                android:layout_marginTop="5pt"
                android:background="@drawable/rounded_button"
                android:backgroundTint="#3399ff"
                android:fontFamily="@font/fira_sans_semibold"
                android:text="Button"
                android:textColor="#f5f5f5"
                android:textSize="8pt" />
</RelativeLayout>

据我所知,将一个对象放在另一个对象之前应该可以,但它没有

【问题讨论】:

    标签: android android-layout android-relativelayout


    【解决方案1】:

    试试这个你需要使用 FrameLayout 来互相重叠视图

       <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <Button
            android:id="@+id/peso_but"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#888"
            android:backgroundTint="#3399ff"
            android:text="Button"
            android:textColor="#f5f5f5"
            android:textSize="8pt" />
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/black"
            android:textColor="@color/white"
             android:gravity="center"
            android:elevation="100dp"
            android:text="1" />
    
    </FrameLayout>
    

    【讨论】:

      【解决方案2】:

      如果您希望 TextViewButton 重叠,请将您的 RelativeLayout 替换为 FrameLayout。

      【讨论】:

        【解决方案3】:

        将此添加到您的按钮

        android:layout_below="@+id/textView"
        

        【讨论】:

          【解决方案4】:

          在 TextView 中试试这一行

          android:layout_abov="@+id/peso_but"
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2013-10-25
            • 2016-11-05
            • 2023-04-06
            • 1970-01-01
            • 2021-11-24
            • 1970-01-01
            • 2017-07-13
            • 1970-01-01
            相关资源
            最近更新 更多