-1
カスタムビューを持つアクティビティにフラグメントを追加しようとしています。フレームレイアウト内のフラグメントを使用してカスタムビューをロードする
private void loadMonitorPage(){
fragmentManager = getFragmentManager();
MonitorFragment monitorFragment = new MonitorFragment();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.MainContentFrameLayout,monitorFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
ここで、MainContentFrameLayoutは、最初の画像で説明した2番目のブロックです。
これは、代わりにこのカスタムビューの(fragment_monitor)
<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"
android:background="@color/colorContentApp"
tools:context="fragments.MonitorFragment">
<monitorView.GridView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorAccent"
/>
</LinearLayout>
これは私のCustomViewクラス
フルスクリーンを覆っている私のフラグメントレイアウトxmlですパブリッククラスGridViewはビューを拡張します{
private Paint mgridpaint;
private float mGridViewWidth;
private float mGridViewHeight;
private Canvas mGridCanvas;
public GridView(Context context) {
super(context);
}
public GridView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public GridView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// TODO: consider storing these as member variables to reduce
// allocations per draw cycle.
int paddingLeft = getPaddingLeft();
int paddingTop = getPaddingTop();
int paddingRight = getPaddingRight();
int paddingBottom = getPaddingBottom();
int contentWidth = getWidth() - paddingLeft - paddingRight;
int contentHeight = getHeight() - paddingTop - paddingBottom;
mgridpaint = new Paint();
mgridpaint.setColor(Color.rgb(0,255,0));
mGridCanvas = canvas;
mGridViewWidth = contentWidth;
mGridViewHeight = contentHeight;
//drawGrid();
}
}
これは私の親レイアウトです。 2番目のFrameLayoutこれを追加する部分
<LinearLayout 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.mactrical.mindoter.MainActivity"
android:weightSum="10"
android:orientation="vertical"
tools:showIn="@layout/app_bar_main">
<FrameLayout
android:id="@+id/ECGDetailsFrameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:background="@color/colorHeaderApp">
</FrameLayout>
<FrameLayout
android:id="@+id/MainContentFrameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="8">
</FrameLayout>
<FrameLayout
android:id="@+id/ECGFooterFrameLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:background="@color/colorFooterApp">
</FrameLayout>
</LinearLayout>
お手伝いをしてください!!!!! :-(
の私の高さ0dpを使用していた問題 を考え出しあなたMainContentFrameLayout xmlファイルを追加 –
@Nabin Khatiwadaを追加しました – Tejas