我试图在android中创建一个应用程序,其中的主活动具有如下的表布局,
第一排: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% )
请帮帮我..。
发布于 2014-02-22 09:03:18
谢谢大家的帮助..。但我有办法解决这个问题。
在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*************/
. . . .
}
. . . .
}https://stackoverflow.com/questions/21944206
复制相似问题