【问题标题】:Custom LinearLayout - inflate layout when children not supplied in XML自定义 LinearLayout - 在 XML 中未提供子项时膨胀布局
【发布时间】:2014-11-26 20:40:56
【问题描述】:

我有一个自定义的线性布局

<com.example.DetailsView
    android:id="@+id/row_ivd_status_details" [...]
    android:orientation="vertical" >
</com.example.DetailsView>

它在构造函数中使用默认布局调用inflate,现在我尝试增​​加在com.example.DetailsView 标签内定义布局的可能性,并检测到它不会膨胀默认布局 - 但它失败了。

我试过了:

Log.i(TAG, "children:"+getChildCount());//also tried with child count
if(findViewById(R.id.ivd_tv_status) == null) {

    inflate(context, R.layout.ivd_layout, this);
}

this 从构造函数中调用。我希望以下布局不调用inflate 方法

<com.example.DetailsView
    android:id="@+id/row_ivd_status_details"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >

    <TextView
        android:id="@+id/ivd_tv_status"
        [...] />


</com.example.DetailsView>

你能建议我根据孩子的存在调用膨胀的方法吗?

【问题讨论】:

    标签: android xml android-layout android-linearlayout


    【解决方案1】:

    似乎正确的地方是onFinishInflate,至少它满足了我的需要。

    【讨论】:

      猜你喜欢
      • 2012-08-27
      • 2012-06-17
      • 1970-01-01
      • 1970-01-01
      • 2011-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-23
      相关资源
      最近更新 更多