私は以下を読んでいますAndroid include layout dynamically with data-binding library質問。私の問題は少し違う。アクティビティのフレームレイアウトをデータバインディングで動的に拡張する方法はありますか?
私は2つのXML活動のための1つ持っている:私はデータバインディングとでframeLayout活動に動的にframe.xmlを膨らまたい
<layout
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="item" type="myapplication.FrameViewModel"/>
</data>
<FrameLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST"/>
</FrameLayout>
</layout>
:フレームの
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="item" type="myapplication.MainActivityViewModel"/>
</data>
<android.support.constraint.ConstraintLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="myapplication.MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/main">
</FrameLayout>
</android.support.constraint.ConstraintLayout>
</layout>
し、別の。言い換えれば、フラグメントのように、断片のない、さまざまなフレームをアクティビティに展開したいと思います。私が活動に示す両方のレイアウトを得ることができるコードで
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityMainBinding activityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
ViewGroup view = activityMainBinding.main;
FrameBinding frameBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.frame,view, false);
}
: は私が活動中で次のことを試してみました。私はアクティビティレイアウトしか見ることができません。アクティビティのレイアウトビュー要素とフレームビュー要素をアクティビティでも表示できるようにするには、コードをどのように変更する必要がありますか?
私はダイナミック表示したいと思いフレーム。 – codeme
@codeme更新された回答を参照してください。私はこれが役立つことを願っています – Cheticamp
ありがとう、非常に便利です。 – codeme