【问题标题】:How do I add a view to a viewParent programmatically?如何以编程方式将视图添加到 viewParent?
【发布时间】:2017-01-04 18:02:26
【问题描述】:

我有一个xml布局文件,如下图

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/homeCoordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivitys.ViewPager.Fragments.Home">
    <com.yalantis.phoenix.PullToRefreshView
        android:id="@+id/pull_to_refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/fragment_dashboard_recycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </android.support.v7.widget.RecyclerView>
    </com.yalantis.phoenix.PullToRefreshView>
</android.support.design.widget.CoordinatorLayout>

我想以编程方式将视图添加到 pulltorefresh 的容器,我已将其添加到我的协调器中,如下所示但我不知道如何将其添加到我的 pulltorefresh 任何想法?

 CoordinatorLayout coordinatorLayout=(CoordinatorLayout)view.findViewById(R.id.homeCoordinatorLayout);
        ImageView imageView=new ImageView(getActivity());
        imageView.setImageResource(R.drawable.ufo);

【问题讨论】:

    标签: android xml view android-coordinatorlayout


    【解决方案1】:
    coordinatorLayout.addView(imageView);
    

    编辑*
    如果您想了解有关该主题的更多信息,可以在这里找到:
    1.ViewManager官方文档。
    2.直截了当Tutorial关于如何通过Mysamplecode添加各种视图。
    3. 相关SO answer在主题上,以防止常见的误解。

    【讨论】:

    • 这并没有提供问题的答案。要批评或要求作者澄清,请在他们的帖子下方留下评论。 - From Review
    • @SuhailMehta,同意!有时我很简单。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-09
    • 2017-06-28
    • 1970-01-01
    • 1970-01-01
    • 2016-07-14
    • 2011-10-05
    相关资源
    最近更新 更多