【问题标题】:SurfaceView inside TableLayoutTableLayout里面的SurfaceView
【发布时间】:2014-02-22 17:03:18
【问题描述】:

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

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

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

第 3 行:1 个表面视图(最多占用 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>   

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

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

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

请帮帮我..

【问题讨论】:

  • 您正在使用嵌套在某些图像视图中的布局权重,但未在这些图像视图中提供关联的 0dp。因此,这三个图像可能会在某些时候遇到该部分代码的问题。我还没有尝试过行中的布局权重。如果它受支持,那么我不会立即看到问题。
  • 我在第二行的图像中使用了布局权重(将 raw 分成 3 个等宽的单元格),它可以毫无问题地显示。我的问题是第 1 行的图像没有显示出来。
  • 我明白了,但是如果没有 0dp 而不是 wrap_content / match_parent 属性,您当前的 ImageView 组件将无法正确使用权重。
  • 好的,我理解您的关注点并在我的代码中进行了更新。
  • 谢谢。但同时你能找出为什么表面视图也利用第一行的空间吗?

标签: android surfaceview tablelayout


【解决方案1】:

感谢大家的帮助.. 但我有解决方法。

在活动的 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*************/
           . . . .
      }
    .  . . . 
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 1970-01-01
    • 2017-04-11
    • 1970-01-01
    • 2012-01-11
    • 2011-03-11
    相关资源
    最近更新 更多