代码之家  ›  专栏  ›  技术社区  ›  Arfmann

安卓-将对象放在相对布局上

  •  -1
  • Arfmann  · 技术社区  · 6 年前

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

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

    我知道,把一个物体放在另一个物体之前应该行得通,但行不通

    I want something like this

    4 回复  |  直到 6 年前
        1
  •  3
  •   Bunny    6 年前

    框架布局 对于彼此重叠的视图

       <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
  •  1
  •   Nazarii Moshenskiy    6 年前

    如果你愿意的话 TextView Button 用FrameLayout替换RelativeLayout。

        3
  •  0
  •   Mohammad Rbabah    6 年前

    android:layout_below="@+id/textView"
    
        4
  •  0
  •   aasifghanchi    6 年前

    在文本视图中尝试这一行

    android:layout_abov="@+id/peso_but"