###前提・実現したいこと
FloatingActionButtonを使用した"Start"アクティビティがあります。
FABをxmlで定義しており、setContentViewで適用しています。
FAB定義のxmlの中程にある<include layout="@layout/content_main" />にて、
"Start"アクティビティにメインで表示したいコンテンツを定義しています。
メインで表示したいコンテンツとは、動的にViewを追加したり削除できるものです。
動的なViewの追加について調べましたが、どの文献を見ても以下のようにコード上でレイアウトを定義し、そのレイアウトに任意のViewをaddView()しています。
LinearLayout linearLayout = new LinearLayout(this);
setContentView(linearLayout);
TextView textView = new TextView(this);
linearLayout.addView(textView);
しかし、今回の私のコードの場合は、既にFABを定義したレイアウトをsetContentViewしてしまっており、上記のように動的追加することはできません。
FABをxmlで定義しsetContentViewしており、尚且つそのxml内でメインのコンテンツxmlをincludeしている場合は、どうようにしてViewを動的に追加すればよいのか教えてください。
###発生している問題・エラーメッセージ
エラーメッセージ
###該当のソースコード
以下がFABを定義しているxmlです。
<?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".Start">
<android.support.design.widget.AppBarLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout>
** <include layout="@layout/content_main" />**
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:orientation="horizontal"> <TextView android:id="@+id/textview2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="invisible" android:layout_marginTop="15dp" android:layout_marginRight="-9dp" android:text="fab2の注釈"/> <android.support.design.widget.FloatingActionButton android:id="@+id/fab2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="160dp" android:layout_gravity="bottom|end" android:layout_marginRight="@dimen/fab2_margin" android:visibility="invisible" app:backgroundTint="@color/colorFAB2" app:elevation="6dp" app:pressedTranslationZ="12dp" android:src="@drawable/ic_fab2" /> </LinearLayout> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" android:orientation="horizontal"> <TextView android:id="@+id/textview1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:visibility="invisible" android:layout_marginTop="15dp" android:layout_marginRight="-2.9dp" android:text="fab1の注釈"/> <android.support.design.widget.FloatingActionButton android:id="@+id/fab1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="90dp" android:layout_gravity="bottom|end" android:layout_marginRight="@dimen/fab1_margin" android:visibility="invisible" app:elevation="6dp" app:backgroundTint="@color/colorFAB1" app:pressedTranslationZ="12dp" android:src="@drawable/ic_fab1" /> </LinearLayout> <android.support.design.widget.FloatingActionButton android:id="@+id/basefab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|end" app:elevation="6dp" app:backgroundTint="@color/colorAccent" app:pressedTranslationZ="12dp" android:layout_margin="@dimen/fab_margin" android:src="@drawable/ic_basefab" />
</android.support.design.widget.CoordinatorLayout>
###試したこと
FABをどうしても使用したいので、どの情報も試せずお手上げ状態です・・・。
###補足情報(言語/FW/ツール等のバージョンなど)
より詳細な情報
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/11/28 14:17
2017/11/28 14:50