Android : Relativelayout in Framelayout not showing up (Custom Camera Preview Screen)
Asked Answered
T

2

6

I need same as I attached image file Its Camera Preview Screen : I want to design two transparent layout over framelayout so it looks like this, but when I run it show only camera screen(Framelayout). It not showing two relative layouts.

<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>
Torus answered 20/3, 2014 at 6:18 Comment(24)
where is your image??Halfpenny
Why did you give a weight to your parent FrameLayout??Farm
i have just uploaded my image. just seeTorus
i have removed weight . still it shows only Framelayout when i run. i am unable to see two relative layout on screen which is transperntTorus
@SandyAngel You mean to say that your both relative layout didn't displayed??Farm
@SandyAngel is it showing in preview in eclipse ideHalfpenny
it showing, please check in real device.Ligniform
@SandyAngel I have tested its working.. You just need to test in your real device rather than run in emulator.Farm
yes,relative layout didn't displayed. it showing in preview in eclipse ide but not when i run in emulator or device :(Torus
ok..wait i will post my answer..Halfpenny
in code how you are loading background image?Ludewig
@RobinHood. Framelayout is my camera preview screen. when i run it. it shows only camera. but not both relative layout. :(Torus
@SandyAngel In which device u r running your app?Farm
@SandyAngel posted my answer just change like that and let me know if you have any doubts..Halfpenny
@SandyAngel In your coding have you set visibility GONE for ur both relative layouts anywhere???Farm
Why are you using Frame Layout. You could use Relative Layout as the Parent Layout because this will also show the desired result. I only use frame layout whenever I need to bring the child views to front or back at runtime.Cougar
@SandyAngel have ur problem solved now?Farm
@SandyAngel set background image for Framelayout statically in your xml file and check and runFarm
@SandyAngel give some feedbackFarm
@Farm I am applying all the answer to my code. thanks for replayTorus
@SandyAngel No but have you set image for Framelayout dynamically?Farm
@Piyush.. Its not Image in the backgroud its video recoder preview screenTorus
@SandyAngel Show me your code. And if it is Video recorder screen then you must be used SurfaceView.Farm
@ PiYusH GuPtA @Harsit Rathhi @ Robin hood and All who tried to solved : Thank you so much for your try. Thanks AgainTorus
H
4

Add ids to the two RelativeLlayouts in layout file..

and get the view object by like this

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

and add this line in your onCreate and test once..

    layout1.bringToFront();
    layout2.bringToFront();
Halfpenny answered 20/3, 2014 at 6:36 Comment(3)
@HarshitRathi SO purpose is to give answer and comment which is perfectly right answer. If any body has doubts or anything problem then he/she can comment to other SO user's answer. So don't behave like kid dude.Farm
@kalyan pvs : Its worked, i have just added id and get view object as you mentioned before frame layout get view object, Thank you so much. you made my day :)Torus
@Kalyan pvs : you are awesomeeeee.. !Torus
A
0

Try this first of all you have to set your background image to 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>

or follow this link.

Astomatous answered 20/3, 2014 at 6:38 Comment(5)
You can't set orientation for FrameLayout.Farm
@Harshit Rathi : Framlayout not contain any images it contains camera preview screen :(Torus
@SandyAngel I have mentioned a link in my answer for what you want.Astomatous
@Kalyan pvs : i am just checking it. Thanks for the answerTorus
@SandyAngel have you follow link which i mentioned.Astomatous

© 2022 - 2024 — McMap. All rights reserved.