繁体   English   中英

Android:Framelayout中的Relativelayout未显示(自定义相机预览屏幕)

[英]Android : Relativelayout in Framelayout not showing up (Custom Camera Preview Screen)

我需要和我附加图像文件一样它的Camera Preview屏幕:我想在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>

将ids添加到布局文件中的两个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>

或点击此链接

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM