TableLayout中的SurfaceView

时间:2014-02-21 20:09:35

标签: android surfaceview tablelayout

我正在尝试在android中创建一个应用程序,其主要活动的表格布局为,

第1行:1张图片(占用屏幕空间的85%)

第二行:3张图片(占用屏幕空间的10%)

第3行:1个surfaceView(占用屏幕空间的5%)

代码: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>   

但是当我运行第一行的应用程序图像时,它会消失并显示:

第1行:3张图片(占用屏幕空间的10%)

第二行:表面视图(占用屏幕空间的90%)

请帮帮我..

1 个答案:

答案 0 :(得分:0)

感谢大家帮忙.. 但我得到了解决方法。

在onCreate活动方法中我更新了以下代码:

 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*************/
           . . . .
      }
    .  . . . 
  }