-3

I've the following XML with various element and I would like to have the only VideoView element expanded in fullscreen (like YouTube) when the device is in landscape mode:

<RelativeLayout 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="#FFFFFF"
    tools:context=".VideoMapPanel" >

    <com.sothree.slidinguppanel.SlidingUpPanelLayout
        xmlns:sothree="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="bottom"
        sothree:panelHeight="68dp"
        sothree:shadowHeight="4dp"
        sothree:paralaxOffset="100dp"
        sothree:dragView="@+id/dragView"
        >

        <!-- MAIN CONTENT -->
        <FrameLayout

            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">
            <android.support.v7.widget.Toolbar
                xmlns:sothree="http://schemas.android.com/apk/res-auto"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:id="@+id/main_toolbar"
                android:layout_height="?attr/actionBarSize"
                android:background="?attr/colorPrimary"
                sothree:theme="@style/ActionBar"
                android:layout_width="match_parent"/>
            <TextView
                android:id="@+id/main"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginTop="?attr/actionBarSize"
                android:gravity="center"
                android:text="Main Content"
                android:clickable="true"
                android:focusable="false"
                android:focusableInTouchMode="true"
                android:textSize="16sp" />


                <fragment
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.MapFragment" />

        </FrameLayout>

        <!-- SLIDING LAYOUT -->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#eeeeee"
            android:orientation="vertical"
            android:clickable="true"
            android:focusable="false"
            android:id="@+id/dragView">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="68dp"
                android:id="@+id/main_title_bar"
                android:orientation="horizontal">

                <TextView
                    android:id="@+id/tvName"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:textSize="20sp"
                    android:textColor="@android:color/white"
                    android:textStyle="bold"
                    android:background="#FF8800"
                    android:gravity="center_vertical"
                    android:paddingLeft="10dp"/>

                       <ProgressBar
            android:id="@+id/progressBar"
            style="?android:attr/progressBarStyleLarge"
            android:layout_width="50dip"
            android:layout_height="match_parent"
            android:gravity="center_vertical"
            android:background="#FF8800"
            android:visibility="gone" >
        </ProgressBar> 

                  <ImageView
                     android:id="@+id/tvLogo"
                     android:layout_width="50dip"
                    android:background="#FF8800"
                     android:layout_height="match_parent"
                     android:paddingRight="10dp"
                     android:gravity="center_vertical" />

            </LinearLayout>


           <VideoView
        android:id="@+id/liveView"
        android:clickable="true"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"/>


            <ImageButton
        android:id="@+id/videoPlayButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@null"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:src="@drawable/videoplaybutton" >
    </ImageButton> 

            <LinearLayout
                android:id="@+id/menuLayout"
                android:background="#FFFFFF"
                android:layout_width="match_parent"
                android:layout_height="68dp"
                android:orientation="horizontal">



                                  <ImageButton
                     android:id="@+id/fbLogo"
                     android:background="#FFFFFF"
                     android:layout_width="fill_parent"
                     android:layout_height="match_parent"
                     android:layout_weight="0.8"
                     android:src="@drawable/facebook_logo"
                     />


                         <ImageButton
                     android:id="@+id/twitterLogo"
                     android:background="#FFFFFF"
                     android:layout_width="fill_parent"
                     android:layout_height="match_parent"
                     android:layout_weight="0.8"
                     android:src="@drawable/twitter_logo"
                     />



                     <ImageButton
                     android:id="@+id/webLogo"
                     android:background="#FFFFFF"
                     android:layout_width="fill_parent"
                     android:layout_height="match_parent"
                     android:layout_weight="0.8"
                     android:src="@drawable/web_logo"/>    

             </LinearLayout>   

     <ScrollView 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

            <com.myapp.tv.ExpandableTextView
                    android:id="@+id/tvDescription"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="14sp"
                    android:textColor="@android:color/black"
                    android:gravity="center_vertical"
                    android:paddingTop="10dp"
                    android:paddingLeft="10dp"
                    android:paddingRight="10dp"/>

            </ScrollView>

 </LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

</RelativeLayout>

Should I solve this programmatically ?

andreasperelli
  • 1,034
  • 2
  • 11
  • 40

1 Answers1

2

I would solve this by using another layout file.

I would start by taking a look at http://developer.android.com/training/basics/supporting-devices/screens.html#create-layouts

Currently I imagine the layout you posted is saved at res/layout/my_layout.xml

What you could do is make another file res/layout-land/my_layout.xml and instead of the same layout define the layout will display the VideoView element in fullscreen. If you are using the other components be sure to include them in the layout or handle null views gracefully in the code. You can include them in the layout by having them in but setting the visibility to gone.

  • I've already tried this solution, but as you noticed in the xml I've a map fragment. So loading a new identical layout (even with visibility:gone for the element) makes the app crash: Caused by: java.lang.IllegalArgumentException: Binary XML file line #51: Duplicate id 0x7f0e0099, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment – andreasperelli Jan 05 '15 at 14:59
  • Are you loading this layout inside a fragment? If you are then, my bad, yes you should solve this programatically. The problem in that case is you have a fragment inside a fragment. http://developer.android.com/about/versions/android-4.2.html#NestedFragments Note: You cannot inflate a layout into a fragment when that layout includes a . Nested fragments are only supported when added to a fragment dynamically. So you'll want a framelayout that you dynamically add that to. – mlaHackingIsMagic Jan 05 '15 at 19:04