Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/218.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 使用ConstraintLayout在按钮顶部显示图片_Android_Xml_Android Layout - Fatal编程技术网

Android 使用ConstraintLayout在按钮顶部显示图片

Android 使用ConstraintLayout在按钮顶部显示图片,android,xml,android-layout,Android,Xml,Android Layout,我试图在Android Studio中使用新的ConstraintLayout将ImageView和TextView置于按钮上方(顶部)。下面是我目前用于我的应用程序的内容,但是相对论对于每个设备大小的布局来说都非常耗时 这是我的XML <FrameLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/frameLayout"

我试图在Android Studio中使用新的
ConstraintLayout
ImageView
TextView
置于按钮上方(顶部)。下面是我目前用于我的应用程序的内容,但是相对论对于每个设备大小的布局来说都非常耗时

这是我的XML

<FrameLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/frameLayout"
    tools:layout_constraintTop_creator="1"
    android:layout_marginStart="48dp"
    android:layout_marginTop="24dp"
    tools:layout_constraintLeft_creator="1"
    ads:layout_constraintLeft_toLeftOf="parent"
    ads:layout_constraintTop_toTopOf="parent"
    android:layout_marginLeft="48dp">


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

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/newfeedbtn"
            android:background="@drawable/newsfeedbtn"
            android:visibility="visible" />
    </FrameLayout>


    <ImageView
        android:layout_width="27dp"
        android:layout_height="25dp"
        android:id="@+id/NFRedC"
        android:layout_gravity="right|top"
        tools:ignore="ContentDescription"
        android:background="@drawable/alert"
        android:gravity="center" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:id="@+id/NFTextNumber"
        android:visibility="invisible"
        android:text="0"
        android:layout_gravity="right|top"
        android:layout_marginRight="9dp"
        android:layout_marginTop="3dp" />


</FrameLayout>

有人知道我可以使用约束实现这一点的方法吗?或者有没有一种方法可以指定图片的显示顺序,而不用在版面中使用版面?e、 g.Microsoft office的“返回发送”

是否有一种方法可以指定图片的显示顺序,而不必在版面中使用版面

这就是FrameLayout自动完成的功能。它从后向前渲染,即按顺序绘制子对象。第一个孩子先画,第二个在上面,第三个在上面

为什么不做如下类似于您已有的操作,但不使用当前包含按钮的冗余FrameLayout

<FrameLayout...>
    <Button/>
    <TextView/>
    <ImageView/>
</FrameLayout>


这有意义吗?还是我误解了你?

我会试试看,上次我这么做时,如果不将图像放在框架布局中,图像就不会显示在按钮上。将发布结果更新。我用它玩了几个小时,没有“冗余框架布局”,无论对象的顺序如何(btn、tv、iv),它都无法工作。ImageView和TextView不会以其他方式显示。我应该使用
src=“”
而不是
background=“”
还是图像按钮?好的,您必须将
按钮更改为
ImageButton
,它会工作的