0

I've had an issue with putting GLSurfaceView between other layouts, as it turned out - it is impossible with GLSurfaceView. So I replaced GLSurfaceView by TextureView, but the issue wasn't solved.

I have such structure in my main layout:

<RelativeLayout android:id="@+id/mainEngineLayout"
                android:layout_width="match_parent"
                android:layout_height="fill_parent"
                android:background="@android:color/transparent"
                tools:context=".activities.MyActivity">

    <com.myapplication.views.openGL.myGLTextureView
            android:id="@+id/myGLTextureView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginLeft="66dp"
            android:layout_marginRight="66dp"/>

    <LinearLayout
            android:id="@+id/leftButtonsLayout"
            android:layout_height="fill_parent"
            android:layout_width="66dp"
            android:layout_alignParentLeft="true"
            android:orientation="vertical"
            android:background="#b7b8b0">

        <ImageButton android:layout_width="66dp"  .../>
        <ImageButton android:layout_width="66dp"  .../>

    </LinearLayout>

    <FrameLayout
            android:layout_height="fill_parent"
            android:id="@+id/rightLayout"
            android:layout_width="wrap_content"
            android:layout_alignParentRight="true"
            android:orientation="vertical"
            android:background="#b7b8b0">

        <ImageButton android:layout_width="66dp"  .../>
        <ImageButton android:layout_width="66dp"  .../>

    </FrameLayout>    

</RelativeLayout>

And finally I want to get result like:

enter image description here

The problem is that on some devices I got problem with not displayed TextureView at all, so that there is black field between left and right layouts.

For example it works in my Samsung S3 and emulators and it doesn't work properly on Xperia. I thought the reason can be in different themes, but I set theme in my manifest file like:

<application
    android:allowBackup="true"
    android:configChanges="orientation|screenSize"
    android:theme="@style/CustomHoloThemeNoActionBar"
    android:screenOrientation="sensorLandscape"
    android:largeHeap="true">
    <activity
        android:theme="@style/CustomHoloThemeNoActionBar"

where "CustomHoloThemeNoActionBar" parent="@android:style/Theme.Holo.Light"

Could you please advise what can cause such issue?

XZen
  • 225
  • 5
  • 27
  • 49
  • i think you can use android:layout_toRightOf to get your layout right to ... and android:layout_toLeftOf to get your layout left to .... replace dots with anther layout id – Mina Fawzy Oct 23 '14 at 13:25
  • In case of using layout_toRightOf and layout_toLeftOf I have to place myGLTextureView after 'left' and 'right' layouts which is not desired for me, I would like to have TextureView as first layout, like background. – XZen Oct 23 '14 at 13:42
  • android:gravity="center" – Mina Fawzy Oct 23 '14 at 13:47
  • this nice link will help you http://sandipchitale.blogspot.in/2010/05/linearlayout-gravity-and-layoutgravity.html – Mina Fawzy Oct 23 '14 at 13:52
  • @minafawzy thank you,so do you think the issue can be caused by not set android:gravity ? – XZen Oct 23 '14 at 14:01
  • yea sir , and cause you right number android:layout_width="66dp" , its not prefer to use any numbers as it will make different from screen to anther , better to use android:layout_weight i will update answer – Mina Fawzy Oct 23 '14 at 14:43
  • 1
    @minafawzy Why do you think it is not prefered to use 'dp' values? I thought 'dp' means 'density independent pixel' which suppose that size won't depend on the display density. – XZen Oct 24 '14 at 08:37

2 Answers2

1

i think you should set gravity or (layout_gravity) to center ,

its depend in how you want it look like

enter image description here

if you want divide them to fix percentage you can use weight property

enter image description here

Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156
  • Unfortunately it didn't help. Actually I didn't understand why gravity can affect the issue with 'overlaping' of TextureView by other layouts – XZen Oct 24 '14 at 09:32
  • then try android:layout_centerInParent="true" , or android:layout_centerHorizontal="true" i hope this work with you – Mina Fawzy Oct 26 '14 at 07:28
1

I have no idea about the OpenGLTextureView, but for your last question i would try to put the TextureView inside a FrameLayout.

I would change the structure of your XML such as (without fill_parent which is deprecated and renamed match_parent in API Level 8 and higher, but it has nothing to do with your problem i think) :

<RelativeLayout android:id="@+id/mainEngineLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/transparent"
                tools:context=".activities.MyActivity">

    <LinearLayout
            android:id="@+id/horizontalContainer"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:orientation="horizontal"
            android:background="#b7b8b0">

       <LinearLayout
               android:id="@+id/leftButtonsLayout"
               android:layout_height="match_parent"
               android:layout_width="wrap_content"
               android:orientation="vertical"
               android:background="#b7b8b0">

             <ImageButton android:layout_width="match_parent"  .../>
             <ImageButton android:layout_width="match_parent"  .../>

        </LinearLayout>

        <FrameLayout
               android:layout_height="match_parent"
               android:id="@+id/textureContainer"
               android:layout_width="match_parent"
               android:background="#b7b8b0">

               <TextureView
                  android:id="@+id/myGLTextureView"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  />
        </FrameLayout> 
        <FrameLayout
               android:layout_height="match_parent"
               android:id="@+id/rightLayout"
               android:layout_width="wrap_content"
               android:orientation="vertical"
               android:background="#b7b8b0">

             <ImageButton android:layout_width="match_parent"  .../>
             <ImageButton android:layout_width="match_parent"  .../>

         </FrameLayout>    
     </LinearLayout>

</RelativeLayout>

But i recommend you to use the java code to make the item sizes dynamic. For instance, in your activity this would give something like this :

private LinearLayout leftLayoutButtonContainer;
private FrameLayout rightLayoutButtonContainer;

private TextureView textureView;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        leftLayoutButtonContainer = findViewById(R.id.leftButtonsLayout);
        rightLayoutButtonContainer = findViewById(R.id.rightLayout);

        textureView = findViewById(R.id.myGLTextureView);

        // Screen dimensions
        display = getWindowManager().getDefaultDisplay();
        size = new Point();
        // Get the screen dimensions between the status bar & the navigation bar.
        display.getSize(size);
        //display.getRealSize(size) if you want to use the size in full screen mode
        // This means without the status and navigation bar counted in the screen size.

       //Get the screen dimensions
       maxWidth = size.x 
       maxHeight = size.y;

       // Call this method in the onCreate() of your activity
       // If you are using Fragment, inside the onActivityCreated() method
       // Which is called after onCreateView() so your items will not be null objects
       setupLayouts();
   }


private void setupLayouts() {

    // If you trully need 66dp, you can let it in XML for your buttons 
    // Then just set the TextureView size such as below
    textureView.getLayoutParams.width = maxWidth - 2 * 66;

    // If you want to set everything dynamically : comment the above line
    // 15% of the width of the screen for both container, so you will have 70% of the screen for your textureView 
    //(from what i see on the picture representing what you want)
    // If you choose the below option, you need to set your Buttons in match_parent in your XML file
    leftLayoutButtonContainer.getLayoutParams.width = maxWidth * 15 / 100; 
    rightLayoutButtonContainer.getLayoutParams.width = maxWidth * 15 / 100;
    textureView.getLayoutParams.width = maxWidth * 70 / 100;


}

Explanations :

The general idea is that in your XML you put the right layouts orientation which will take care of the "order" of the elements.

That's what the main LinearLayout with android:orientation="horizontal" is doing.

Then, you want to set all of the elements with the match_parent attribute & you set the size of the item you want with %.

It's the idea & probably the maths that are behind the attributes weight in XML but i never it because i like sometimes to control my items at any moment with my maths.

Hope this helps !

Tom3652
  • 2,540
  • 3
  • 19
  • 45