框架布局上的按钮

时间:2013-12-05 08:15:10

标签: android xml android-framelayout

您好我正在开发一个Android视频应用程序。我的框架布局上有按钮。我需要按钮有点大。但是当我在屏幕上进行预览时,它们会逐渐缩小。 Video.xml如下所示

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <FrameLayout
        android:id="@+id/videoview"
        android:layout_width="720px"
        android:layout_height="480px" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/mybutton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:paddingLeft="2dp"
            android:paddingRight="2dp"
            android:src="@drawable/record_video" />

        <RadioGroup
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <RadioButton
                android:id="@+id/flashoff"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="OFF"
                android:textSize="8dp" />

            <RadioButton
                android:id="@+id/flashtorch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Torch"
                android:textSize="8dp" />
        </RadioGroup>
    </LinearLayout>
</LinearLayout>

和oncreate如下

public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    setContentView(R.layout.videocapture);
    DisplayMetrics metrics = this.getResources().getDisplayMetrics();
    vwidth = metrics.widthPixels;
    vheight = metrics.heightPixels;

    Log.e("vwidth"," "+vwidth);
    Log.e("vheight"," "+vheight);

    //Get Camera for preview
    myCamera = getCameraInstance();
    if(myCamera == null)
    {
        Toast.makeText(VideoCapture.this,"Fail to get Camera",Toast.LENGTH_LONG).show();
    }


    myCameraSurfaceView = new MyCameraSurfaceView(this, myCamera);
    final FrameLayout myCameraPreview = (FrameLayout)findViewById(R.id.videoview);
    myCameraPreview.addView(myCameraSurfaceView);
    myCameraPreview.post(new Runnable()
    {
        @Override
        public void run()
        {             
            int width = vwidth;
            int height = vheight;                
            LayoutParams lp = myCameraPreview.getLayoutParams(); 
            lp.height = height;
            lp.width = width - 80;
            myCameraPreview.setLayoutParams(lp);
        }

    });

    recVideo = (ImageView)findViewById(R.id.mybutton);
    recVideo.setOnClickListener(myButtonOnClickListener);

    flashOff = (RadioButton)findViewById(R.id.flashoff);
    flashTorch = (RadioButton)findViewById(R.id.flashtorch);
}

我该如何解决这个问题。请帮忙。感谢

1 个答案:

答案 0 :(得分:0)

尝试使用此布局,您可以根据您的要求改变重量。请更改背景颜色。希望它会有所帮助。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <FrameLayout
        android:id="@+id/videoview"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="3"
        android:background="#FFCCCC" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#99FF66"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/mybutton"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="2dp"
            android:paddingRight="2dp"
            android:src="@drawable/ic_launcher" />

        <RadioGroup
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <RadioButton
                android:id="@+id/flashoff"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="OFF"
                android:textSize="8dp" />

            <RadioButton
                android:id="@+id/flashtorch"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Torch"
                android:textSize="8dp" />
        </RadioGroup>
    </LinearLayout>

</LinearLayout>