2014-02-21 20 views
0

我試圖創造機器人具有表佈局的應用程序,與主要活動,SurfaceView內TableLayout

第一行:1倍的圖像(這將需要最多的屏幕空間85%)

第二行:3倍的圖像(其將需要最多的屏幕空間10%)

第三行: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> 

但是當我運行第一行的應用程序圖像被消失,並且它示出了:

第一行:3幅圖像(這需要高達的屏幕空間10%)

第二行:表面視圖(這需要高達90%的屏幕空間)

請請幫我..

+0

您正在使用嵌套在一些你的圖像視圖佈局權重,但不提供這些imageviews內的相關0dp。因此,這三個圖像可能會在某個時間點出現在代碼段。我還沒有嘗試過行中的佈局權重。如果它的支持,那麼我沒有看到一個直接的問題。 –

+0

我已經在第二行的圖像中使用了佈局權重(在3個相等寬度的單元格中劃分原始數據),其中沒有任何問題顯示。我的問題是行1的圖像沒有顯示出來。 –

+0

我承諾,但是如果沒有0dp而不是wrap_content/match_parent屬性,您當前的ImageView組件將不會正確使用權重。 –

回答

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