1
Im使用Caldroid庫。我想在我的佈局中使用它。我的佈局還包括textview。但是當我用framelayout使用Caldroid時,其他視圖都消失了。在片段內使用Caldroid
這裏是使用Caldroid和FrameLayout的XML和Java代碼。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.birfincankafein.mpandroidchart.CalendarFragment"
android:orientation="vertical">
<!-- TODO: Update blank fragment layout -->
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="@+id/container_caldroid"
android:layout_weight="0.4">
</FrameLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="@+id/imageView_divider"
android:layout_below="@+id/container_caldroid"
android:focusableInTouchMode="false"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="0.1"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/imageView_divider"
android:background="#ffff00ba"
android:layout_weight="0.4">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView_description"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#ff00ebff"/>
</RelativeLayout>
這裏是Java代碼:
mCaldroidFragment = new CaldroidFragment();
Bundle args = new Bundle();
args.putInt(CaldroidFragment.START_DAY_OF_WEEK, CaldroidFragment.MONDAY);
mCaldroidFragment.setArguments(args);
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.container_calendar , mCaldroidFragment).commit();
這裏是什麼樣子:
這些是使用Caldroid與片段編碼。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.birfincankafein.mpandroidchart.CalendarFragment"
android:orientation="vertical">
<!-- TODO: Update blank fragment layout -->
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
class="com.roomorama.caldroid.CaldroidFragment"
android:id="@+id/container_caldroid"
android:layout_weight="0.4">
</fragment>
<ImageView
android:layout_width="match_parent"
android:layout_height="1dp"
android:id="@+id/imageView_divider"
android:layout_below="@+id/container_caldroid"
android:focusableInTouchMode="false"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:layout_weight="0.1"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/imageView_divider"
android:background="#ffff00ba"
android:layout_weight="0.4">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView_description"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#ff00ebff"/>
</RelativeLayout>
而且也沒有必要Java代碼。它已經初始化。以下是它的外觀:
爲什麼會發生這種情況?我想在框架佈局中使用這個庫。因爲我必須手動初始化它。我必須設定一些瑣碎的事情。
ps:背景顏色用於檢測佈局的位置。