自定义视图没有奇怪的布局行为

时间:2019-02-06 14:52:47

标签: android layout android-custom-view android-constraintlayout

基本上,我有一个自定义的视图类(MessageViewAudio),它扩展了ConstraintLayout。该自定义视图包含另一个ConstraintLayout,其中包含我创建的另一个自定义视图(AudioVisualizationView)。问题是“顶层自定义视图”(MessageViewAudio)总是在右边有一些空间。我附上了布局检查员给我的信息。如果您需要更多代码,请告诉我。

如上所述,我检查了布局并尝试了不同类型的容器,并手动尝试从上述每个视图中删除边距和填充。但是布局检查员已经说过,没有多余的边距填充会导致这种奇怪的行为。 有两种方法可以使它起作用:一种:删除所有容器,然后仅添加AudioVisualizationView自定义视图。第二:从MessageViewAudio的LayoutParams中删除属性constrainedWidth = true。现在我需要constrainedWidth = true,但是我有一种感觉,这个属性有点问题,我不能仅仅弄清楚为什么constrainedWidth会导致这种行为。

带容器

不起作用

The hierarchy

层次结构

The hierarchy

ChatMessage

The layout

MessageViewAudio

The layout

audioContent

The layout

visualizationView

The layout

没有容器

工作

Working

我现在只能提供的代码是视图的xml: audioContent +可视化视图:

<com.jooyapp.jooy.custom_views.RoundedConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/audioContent"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:backgroundColor="@color/colorAccent"
    app:radius="20">

    <!--android:paddingStart="10dp"-->
    <!--android:paddingTop="10dp"-->
    <!--android:paddingEnd="10dp"-->
    <!--android:paddingBottom="10dp"-->

    <com.jooyapp.jooy.custom_views.AudioVisualizationView
        android:id="@+id/visualizationView"
        android:layout_width="wrap_content"
        android:background="@color/light_grey"
        android:layout_height="wrap_content" />

</com.jooyapp.jooy.custom_views.RoundedConstraintLayout>

所有其他内容都是通过编程方式创建的

总的来说,我的问题是我不知道自定义视图右侧的空间在哪里。

0 个答案:

没有答案
相关问题