首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SurfaceView内部TableLayout

SurfaceView内部TableLayout
EN

Stack Overflow用户
提问于 2014-02-21 20:09:34
回答 1查看 327关注 0票数 0

我试图在android中创建一个应用程序,其中的主活动具有如下的表布局,

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

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

第三排:1 surfaceView (将占用屏幕空间的5% )

代码: MainLayout.xml

代码语言:javascript
复制
<?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>   

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

第一排:3张图片(占屏幕空间的10% )

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

请帮帮我..。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-02-22 09:03:18

谢谢大家的帮助..。但我有办法解决这个问题。

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

代码语言:javascript
复制
 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*************/
           . . . .
      }
    .  . . . 
  }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21944206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档