【问题标题】:buttons on frame layout框架布局上的按钮
【发布时间】:2013-12-05 08:15:10
【问题描述】:

您好,我正在开发一款安卓视频应用。我的框架布局上有按钮。我需要大一点的按钮。但是当我在屏幕上看到预览时,它们正在缩小。 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);
}

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

【问题讨论】:

  • FrameLayout 在你的情况下似乎没有孩子。
  • 需要修正 FrameLayout 的高度和宽度吗?
  • 您的应用仅支持横向模式吗?你为什么使用 720 像素和 480 像素?
  • android-er.blogspot.in/2011/10/… 我参考了上面的链接,是的,我正在横向模式下尝试

标签: android xml android-framelayout


【解决方案1】:

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

<?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>

【讨论】:

  • 试过了!但它针对不同的手机显示不同。在某些方面非常完美。但在小型手机上非常大。我该如何解决?
  • 什么是非常大的视频视图或按钮?
  • 它的高度是 matchparent,您可以使用任何值设置它,宽度将取决于两个子布局的权重。更改这些值以满足您的要求。
  • LayoutParams lp = myCameraPreview.getLayoutParams(); lp.height = 高度; lp.width = 宽度 - 80;通过使用它来改变框架布局高度?
猜你喜欢
  • 2019-04-22
  • 1970-01-01
  • 2015-07-22
  • 2016-09-02
  • 2011-07-03
  • 2020-01-13
  • 1970-01-01
  • 2012-04-10
  • 1970-01-01
相关资源
最近更新 更多