FrameLayout in ViewSwitcher doesn't resize on switching!

  • Replies:0
Doug Ponsford
  • Forum posts: 2

Nov 10, 2012, 11:56:46 AM via Website

Hi All, I have a problem with a FrameLayout inside a LinearLayout/ViewSwitcher which has been dogging me for days! Any help would be appreciated:

In the XML, I have a LinearLayout that defines a background theme, a ViewSwitcher inside that, and a LinearLayout in the first (upper) half of the ViewSwitcher. The upper half of the ViewSwitcher has several TextViews and a FrameLayout which places the frame in the bottom-right-hand corner of the screen. I insert a live image from the camera into that FrameLayout. So far, so good!

The 2nd half of the ViewSwitcher only has a single FrameLayout in it, in which I also insert the live camera view. I want this 2nd FrameLayout to fill the screen inside the background - but it doesn't.

The first screen and the swiping between the 2 switchable views works OK, but I can't get the single FrameLayout in the 2nd screen to fill the view (the background theme has a full-width button at the top and bottom - this displays OK). The 2nd switched view still has the small video frame in it. I've tried everything I can think of and searched what feels like every single relevant post on the forum, but I can't get the 2nd FrameLayout to fill the screen.

I've tried putting the 2nd FrameLayout inside it's own LinearLayout, but to no avail.

If I move the single FrameLayout to the upper half of the ViewSwitcher (so that it appears first on onCreate), then I get the full-screen video image that I want, but then switching to the 2nd view gives me no video frame at all (but all the text views are there)!

Setting android:measureAllChildren="false" in the XML and switcher.setMeasureAllChildren(false); in the code makes no difference.

Here's the XML...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="..... android.com/apk/res/android...."
style="@style/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ViewSwitcher
android:id="@+id/viewswitcher"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:measureAllChildren="false"
android:layout_weight="1" >

<!--
***************
V I E W O N E
***************
-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="1sp"
android:orientation="horizontal" >

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginRight="5sp"
android:orientation="vertical" >

<TextView
android:id="@+id/txt1"
style="@style/normaltext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="1sp"
android:text="@string/str1" />
....
....
<TextView
android:id="@+id/txt3"
style="@style/normaltext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="1sp"
android:text="@string/str2" />
</LinearLayout>

<LinearLayout
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_marginLeft="1sp"
android:layout_marginRight="1sp"
android:layout_weight="0.38"
android:orientation="vertical" >

<TextView
android:id="@+id/txt4"
style="@style/normaltext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1sp" />
....
....

<TextView
android:id="@+id/txt5"
style="@style/normaltext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="1sp"
android:text="@string/str3" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >

<FrameLayout
android:id="@+id/camimage"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</FrameLayout>

</LinearLayout>

</LinearLayout>

</LinearLayout>

<!--
***************
V I E W T W O
***************
-->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:measureAllChildren="false"
android:layout_weight="1" >

<FrameLayout
android:id="@id/camimage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</FrameLayout>

</LinearLayout>

</ViewSwitcher>

<Button
android:id="@+id/colour"
style="@style/button_style"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="@string/ButtonDefault" />

</LinearLayout>

I'm sure it's just a case of the Switcher taking the size of the first FrameLayout instance it sees and then it's stuck with that for both views, but I can't find a way to get it to resize the FrameLayout to fill the screen on the 2nd view.

Can anybody help with this?

Reply