Android 缩放儿童的线性布局,使其适合屏幕

Android 缩放儿童的线性布局,使其适合屏幕,android,android-linearlayout,Android,Android Linearlayout,嗨,我正在尝试制作一个底部带有AdMob横幅的游戏菜单。我想在水面上画菜单。为了将横幅和表面视图分开,我使用了线性布局。问题是SurfaceView是全屏的,并将横幅推到屏幕底部之外。是否有缩放SurfaceView的方法,使其不会将横幅推到屏幕外?SurfaceView高度-横幅高度。 这是我的密码: linearLayout = new LinearLayout(this); linearLayout.setId(Constants.LINLAY_ID); linea

嗨,我正在尝试制作一个底部带有AdMob横幅的游戏菜单。我想在水面上画菜单。为了将横幅和表面视图分开,我使用了线性布局。问题是SurfaceView是全屏的,并将横幅推到屏幕底部之外。是否有缩放SurfaceView的方法,使其不会将横幅推到屏幕外?SurfaceView高度-横幅高度。 这是我的密码:

    linearLayout = new LinearLayout(this);
    linearLayout.setId(Constants.LINLAY_ID);
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    contentView = new ContentView(this);

    AdView adView = new AdView(this);
    adView.setAdSize(AdSize.BANNER);
    adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);

    linearLayout.addView(contentView);
    linearLayout.addView(adView);
    setContentView(linearLayout);
` 注意:如果我将其更改为:

linearLayout.addView(adView);
linearLayout.addView(contentView);
横幅显示在顶部,SurfaceView被向下推了一点。
感谢您的回答:

在线性布局中使用布局权重,如下所示:

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <SurfaceView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="4"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>
    </LinearLayout>

这里第三个参数是布局权重

如果你想让你的SurfaceView全屏显示,那么使用线性布局,你不能在视图顶部显示其他视图使用框架布局,将你的横幅添加到底部,并添加曲面视图以匹配父视图,但横幅不会覆盖底部的SurfaceView吗?确定,然后只使用线性布局布局重量与高度之比为0dp很抱歉我不能胜任这个xD,但你知道我如何在Java代码中设置所有这些吗。因为我在代码中创建了一个扩展SurfaceView的类SurfaceView注意:我用xml尝试了它,它很管用,但是我不能同时使用这两个视图我需要它们。谢谢!完美作品:
LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
    LayoutParams.MATCH_PARENT,
    0f,
    1.0f
);
YOUR_VIEW.setLayoutParams(param);