Android: Relativelayout в Framelayout не отображается (пользовательский экран предварительного просмотра камеры)

Мне нужно то же самое, что и прикрепленный файл изображения на экране предварительного просмотра камеры : я хочу создать два прозрачных макета над framelayout, чтобы это выглядело так, но при запуске он показывает только экран камеры(Framelayout). Он не показывает два относительных макета.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/camera_preview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:layout_gravity="top"
        android:padding="15dp" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="01"
            android:textColor="@color/White" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/textView1"
            android:layout_marginTop="5dp"
            android:text="Status:"
            android:textColor="@color/White" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/textView1"
            android:layout_marginRight="78dp"
            android:src="@drawable/heart" />

        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/textView2"
            android:layout_alignLeft="@+id/imageView3"
            android:layout_marginTop="10dp"
            android:src="@drawable/view" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/imageView3"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@+id/imageView4"
            android:text="125 Likes"
            android:textColor="@color/White" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/textView2"
            android:layout_toRightOf="@+id/textView2"
            android:text="STREAMING" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView3"
            android:layout_alignTop="@+id/imageView4"
            android:text="24 Viewers"
            android:textColor="@color/White" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#77000000"
        android:layout_gravity="bottom"
        android:padding="10dp" >

        <Button
            android:id="@+id/button_capture"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:background="@drawable/camera_record"
            android:textColor="@color/White" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="50dp"
            android:src="@drawable/view_video_big" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="50dp"
            android:src="@drawable/swipe_camera" />
    </RelativeLayout>

</FrameLayout>

2 ответов


добавить идентификаторы к двум RelativeLlayouts в файле макета..

и получить объект вида, как это

    RelativeLayout layout1=(RelativeLayout) findViewById(R.id.topRelativeLayout);
    RelativeLayout layout2=(RelativeLayout) findViewById(R.id.bottomRelativeLayout);

и добавьте эту строку в свой onCreate и проверьте один раз..

    layout1.bringToFront();
    layout2.bringToFront();

попробуйте это, прежде всего, вы должны установить фоновое изображение для FrameLayout:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/camera_preview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" 
    android:background="@drawable/ic_launcher"
     >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:padding="15dp" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="01"
            android:textColor="@color/White" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/textView1"
            android:layout_marginTop="5dp"
            android:text="Status:"
            android:textColor="@color/White" />

        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignTop="@+id/textView1"
            android:layout_marginRight="78dp"
            android:src="@drawable/heart" />

        <ImageView
            android:id="@+id/imageView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/textView2"
            android:layout_alignLeft="@+id/imageView3"
            android:layout_marginTop="10dp"
            android:src="@drawable/view" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/imageView3"
            android:layout_marginLeft="10dp"
            android:layout_toRightOf="@+id/imageView4"
            android:text="125 Likes"
            android:textColor="@color/White" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/textView2"
            android:layout_toRightOf="@+id/textView2"
            android:text="STREAMING" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/textView3"
            android:layout_alignTop="@+id/imageView4"
            android:text="24 Viewers"
            android:textColor="@color/White" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#77000000"
        android:layout_gravity="bottom"
        android:visibility="visible"
        android:padding="10dp" >

        <Button
            android:id="@+id/button_capture"
            android:layout_width="70dp"
            android:layout_height="70dp"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:background="@drawable/camera_record"
            android:textColor="@color/White" />

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="50dp"
            android:src="@drawable/view_video_big" />

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="50dp"
            android:src="@drawable/swipe_camera" />
    </RelativeLayout>

</FrameLayout>

или следовать этому ссылке.