Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何将一个按钮覆盖在另一个按钮上_Android_Android Layout - Fatal编程技术网

Android 如何将一个按钮覆盖在另一个按钮上

Android 如何将一个按钮覆盖在另一个按钮上,android,android-layout,Android,Android Layout,我想要两行0到9个按钮。每个按钮在右下角有另一个小按钮的叠加。当我单击按钮时,叠加按钮上将显示计数。对不起,我的英语不好,提前谢谢 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_heig

我想要两行0到9个按钮。每个按钮在右下角有另一个小按钮的叠加。当我单击按钮时,叠加按钮上将显示计数。对不起,我的英语不好,提前谢谢

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     android:orientation="horizontal">
   <LinearLayout
    android:id="@+id/expandable2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
      RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <Button
                android:id="@+id/btn0"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0" />

            <Button
                android:layout_width="25dp"
                android:layout_height="25dp"
                android:layout_alignBottom="@id/btn0"
                android:layout_alignRight="@id/btn0"
                android:background="#FFFFFF"
                android:text="0" />
        </RelativeLayout>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="3" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="4" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="5" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="6" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="7" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="8" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="9" />
    </LinearLayout>
    </LinearLayout>
    </LinearLayout>
我的输出


任何其他建议都将不胜感激

尝试将其设置为这样

 android:layout_marginLeft="-20dp"
 android:layout_marginTop="10dp"
使用框架布局

<FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true">

        <Button
            android:id="@+id/icon_image"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_margin="5dp"
            android:background="@color/black"
            android:text="0" />

        <Button                
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_gravity="bottom|right"
            android:background="@color/white"
            android:layout_marginLeft="6dp"
            android:src="@drawable/ic_goal_check" />
    </FrameLayout>
现在,您可以在布局中使用

<yourPackageName.YourButton
      android:id="@+id/button_one"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" />

这将使您的主布局简单整洁。

使用文本视图显示计数,因为按钮上的按钮没有意义。 不管怎么说,这是怎么表现出来的

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

<Button 
android:layout_width = "match_parent"
android:layout_height="match_parent"
android:id="@+id/btn"/>
<Button
android:layout_width = "wrap_content"
android:layout_height="wrap_content"
android:id="@+id/countbtn"
android:layout_alignParentBottom="true"
android:layout_alignParentRight= "true"/>

</RelativeLayout>
在网格或RecyclerView适配器中使用此视图,使其显示为您希望显示的10倍


如果要使用TextView显示计数,请删除countBtn并使其成为最后两个属性相同的TextView。

您可以使用framelayout包含两个按钮,并对所有按钮使用网格布局,无需对按钮中的allA按钮进行布局。。。你要设计一个多么糟糕的用户界面。是的,兄弟,这是一个糟糕的用户界面……我是android新手,在那里可以完全了解用户界面设计。使用谷歌搜索教程。或者是UI设计技巧。你在开玩笑吧………我希望任何特定的网站都能研究UI设计。我会相应地调整宽度和高度,使其与父级和60dp相匹配。你可以像现在一样使用水平线性布局
<RelativeLayout
android:layout_width = "match_parent"
android:layout_height = "60dp">

<Button 
android:layout_width = "match_parent"
android:layout_height="match_parent"
android:id="@+id/btn"/>
<Button
android:layout_width = "wrap_content"
android:layout_height="wrap_content"
android:id="@+id/countbtn"
android:layout_alignParentBottom="true"
android:layout_alignParentRight= "true"/>

</RelativeLayout>