【发布时间】:2016-04-05 18:55:34
【问题描述】:
我有一个扩展RelativeLayout 的自定义视图。在该类的 init(Context context, AttributeSet attrs) 方法中,我通过以下方式设置布局文件:
inflate(getContext(), R.layout.in_session_view_layout, this);
我在这样的列表项中使用这个自定义视图:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:verizon="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_margin="5dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageView
android:id="@+id/flag"
android:layout_width="60dp"
android:layout_height="160dp"
android:layout_below="@id/txt"
android:layout_gravity="center"
android:layout_margin="5dp" />
</FrameLayout>
<com.widgets.FreeBeeNotificationView
android:id="@+id/freebee_pre_session_view"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_gravity="right|top"
android:layout_marginBottom="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="6dp"
verizon:textSize="12sp" />
</FrameLayout>
现在,要求是,需要根据用户输入在自定义视图中动态设置此布局文件。但是,在自定义视图的 init() 方法已经被调用后,我收到了用户输入,因为一旦加载了上面给出的 FrameLayout,这个方法就会被调用。
如何根据用户输入将布局文件动态设置为自定义视图?谁能帮帮我。
谢谢。
【问题讨论】:
-
您需要先对 R.layout.in_session_view_layout 进行膨胀,然后当用户输入到达时再对另一个布局进行膨胀,还是在用户输入到达后只需对 R.layout.in_session_view_layout 进行膨胀?
-
我有 2 种布局:R.layout.in_session_view_layout_1 和 R.layout.in_session_view_layout。用户输入到达后,任何一个都需要在视图中膨胀。
标签: android android-layout android-custom-view