Question

I am trying to create an application in android, with main activity which has table layout as,

1st Row: 1 image (which will take upto 85% of screen space)

2nd Row: 3 images (which will take upto 10% of screen space)

3rd Row: 1 surfaceView (which will take upto 5% of screen space)

Code: MainLayout.xml

<?xml version="1.0" encoding="utf-8"?>


 <TableLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/fullscreen_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_vertical|center_horizontal"
        android:background="@color/white"

        android:stretchColumns="*"
        android:shrinkColumns="*"

        >
 <TableRow
    android:id="@+id/tableRow1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.85"
    android:gravity="top|center"
     >  


  <ImageView
  android:id="@+id/icamera"
  android:scaleType="fitXY" 
  android:layout_width="match_parent"
  android:layout_height="match_parent" 
  android:src="@drawable/cam_off"
  android:layout_column="0"
  android:layout_span="3"
  android:layout_gravity="center|top" 
  android:paddingTop="0sp"
  android:paddingRight="0sp"
  android:paddingLeft="0sp"
  android:paddingBottom="0sp"
  />


</TableRow> 

 <TableRow
    android:id="@+id/tableRow2"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.10"
    android:gravity="bottom|center"
     >      
   <ImageView
  android:id="@+id/isetting"
  android:scaleType="centerInside"  
  android:layout_width="wrap_content"
  android:layout_height="0dp" 
  android:src="@drawable/settings"
  android:layout_column="0"
  android:layout_weight="0.30"
  android:layout_gravity="left|bottom" 

  android:paddingTop="0sp"
  android:paddingRight="0sp"
  android:paddingLeft="0sp"
  android:paddingBottom="0sp"
  />

  <ImageView
  android:id="@+id/icredits"
  android:scaleType="centerInside"  
  android:layout_width="wrap_content"
  android:layout_height="0dp" 
  android:src="@drawable/credits"
  android:layout_gravity="center|bottom"
  android:layout_column="1"
  android:layout_weight="0.30"

  android:paddingTop="0sp"
  android:paddingRight="0sp"
  android:paddingLeft="0sp"
  android:paddingBottom="0sp"
  />

  <ImageView
  android:id="@+id/ihelp"
  android:scaleType="centerInside"  
  android:layout_width="wrap_content"
  android:layout_height="0dp" 
  android:src="@drawable/help"
  android:layout_column="2"
  android:layout_gravity="center|bottom"
  android:paddingTop="0sp"
  android:paddingRight="0sp"
  android:paddingLeft="0sp"
  android:paddingBottom="0sp"
  android:layout_weight="0.30"
  /> 

 </TableRow>  

  <TableRow
    android:id="@+id/tableRow3"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="0.05"
    android:layout_gravity="bottom"
     > 

<SurfaceView 
    android:id="@+id/surfaceView2" 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_column="0"
  android:layout_span="3"
    android:layout_gravity="bottom"
  android:background="@color/black"
  android:scaleType="fitXY" 
  android:paddingTop="0sp"
  android:paddingRight="0sp"
  android:paddingLeft="0sp"
  android:paddingBottom="0sp">
</SurfaceView>

 </TableRow>

</TableLayout>   

but when I run the application image of 1st row gets disappear and it shows:

1st Row: 3 Images (which takes upto 10% of screen space)

2nd Row: Surface view (which takes upto 90% of screen space)

Kindly please help me out..

Was it helpful?

Solution

Thanks for everyone for helping.. but I got workaround for this.

in onCreate method of activity i updated following code:

 public class MainScreenActivity extends Activity 
{
private static final String TAG = "Recorder";
public static SurfaceView mSurfaceView;
public static SurfaceHolder mSurfaceHolder;
public static Camera mCamera ;
public static boolean mPreviewRunning;
public static SharedPreferences sharedPref;
public static Display display;
public static  int swidth,sheight;

@Override
public void onCreate(Bundle savedInstanceState)
{
    // Requires import android.view.Window
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.mainscreen_layout);




    mSurfaceView = (SurfaceView) findViewById(R.id.surfaceView2);
    mSurfaceHolder = mSurfaceView.getHolder();



            /*************added code*************/      
    display = getWindowManager().getDefaultDisplay();

    @SuppressWarnings("deprecation")
     int width = display.getWidth(); // ((display.getWidth()*20)/100)
    @SuppressWarnings("deprecation")
     int height = display.getHeight();// ((display.getHeight()*30)/100)

    swidth = width;// width*10/100;
    sheight = height*5/100;//height*15/100;
    TableRow.LayoutParams lp = new TableRow.LayoutParams(swidth,sheight);
    lp.span=3;
    lp.column=0;
    lp.weight=0.05f;
    mSurfaceView.setLayoutParams(lp);
            /*************added code*************/
           . . . .
      }
    .  . . . 
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top