如何将android布局的元素放在另一个元素上

问题描述

我有以下问题:我想将CardView放在另一个Android布局文件中。 所以在android studio布局编辑器中,结果就是这个,这就是我想要的: cardView在矩形CardView的右上角围绕同一高度

What I want

但是如果我启动模拟器,结果是这样的:

the result I get

这是两个cardView的代码

    <androidx.cardview.widget.CardView
        android:id="@+id/dati1h"
        android:layout_width="300dp"
        android:layout_height="483dp"
        android:layout_marginTop="90dp"
        android:layout_marginBottom="162dp"
        app:cardCornerRadius="8dp"
        app:cardElevation="5dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.5"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

    </androidx.cardview.widget.CardView>

    <androidx.cardview.widget.CardView
        android:id="@+id/info"
        android:layout_width="40dp"
        android:layout_height="40dp"
        app:cardCornerRadius="100dp"
        app:layout_constraintBottom_toBottomOf="@id/dati1h"
        app:layout_constraintEnd_toEndOf="@id/dati1h"
        app:layout_constraintStart_toStartOf="@id/dati1h"
        app:layout_constraintTop_toTopOf="@id/dati1h"
        android:layout_marginBottom="480dp"
        android:layout_marginStart="290dp"
        android:clickable="true"
        android:focusable="true"
        app:cardElevation="5dp">

        <androidx.appcompat.widget.AppCompatimageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/ic_info_foreground"/>
    </androidx.cardview.widget.CardView>

我真的不知道该怎么解决。感谢您的帮助!

解决方法

如何制作RelativeLayout

library("Biostrings")
myseq<-DNAString("ATGACGTGTTCGTGT") #Read string as DNAstring object
myaa<-translate(myseq) #Translate to aa
my3laa<-AMINO_ACID_CODE[unlist(strsplit(as.character(myaa),NULL))] #Get 3-letter code
,

info之后声明dati1h CardView时,我看不到代码有问题,这意味着信息cardView应该通过dati1h呈现。但这可能是设备特定的问题,我之前也遇到过类似的问题(对于约束布局)。

要解决此问题,我选择增加一定可以解决的高程。

但是,由于您不想遵循这种方法,请尝试使用Frame / Relative Layout作为CardView的父级(而不是约束布局),它应该可以解决您的问题。