简体   繁体   English

Android CustomView显示两次

[英]Android CustomView is shown twice

I created a CustomView which I added to the XML Layout. 我创建了一个CustomView,我将其添加到XML Layout中。 It is all a very simple layout which shouldn't show any problems. 这是一个非常简单的布局,不应该显示任何问题。 Still, what irritates me is that some elements seem to be added twice to the layout (within itself). 然而,令我恼火的是,有些元素似乎被添加了两次布局(在其内部)。

The XML looks like this: XML看起来像这样:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/activityLayoutRL">

    <world.b2g.b2gether.ui.RadarQuickInfo
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/radarDetailView"
        android:visibility="visible"/>

</RelativeLayout>

在此输入图像描述

The view itself is simply extending a LinearLayout and is initialized like this: 视图本身只是扩展一个LinearLayout并初始化如下:

 public void initView(Context context){
    this.context = context;
    LayoutInflater inflater = (LayoutInflater)
            context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.radar_detail_layout, this);
}

It sometimes seems to change when switching to another build number. 切换到另一个内部版本号时,有时似乎会发生变化。 I develop for API level 23 but changing to 22 sometimes seems to solve it (at least sometimes) 我为API级别23开发,但有时候改为22可以解决它(至少有时候)

So I created this constructor 所以我创建了这个构造函数

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public RadarQuickInfo(Context context, AttributeSet attrs, 
    int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    initView(context);
}

The Layout of the custom view doesn't seem to change anything. 自定义视图的布局似乎没有任何改变。 So even this causes this effect: 所以即使这会导致这种效果:

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

</LinearLayout>

I assume, there might be an error somewhere? 我想,某处可能有错误? Any ideas? 有任何想法吗?

使用<merge>包装自定义视图的布局

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM