线性布局的线性布局无法正确显示重量

时间:2016-04-14 16:13:40

标签: android xml android-layout

我试图创建一个垂直线性布局,其中包含多个按钮的水平线性布局,底部是横幅广告。但我所做的显然不起作用。在下面的屏幕截图中,它基本上是我想要它在预览中,但在模拟器中它不会出来,就像我想要它留下了很多空白。 https://gyazo.com/468c575c8f56f167b8ff029e076b964f

因此,如果任何人都有一个很棒的解决方案,我真的会陷入困境。

*注意忽略字符串名称和按钮名称中的粗俗,这适用于音板应用程序。

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.android.soundboard.MainActivity"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:orientation="vertical"
android:paddingTop="2dp"
android:paddingBottom="2dp"
android:layout_weight="1"
android:weightSum="12"
>

<!-- a lot of buttons -->

<!-- row 1 -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="1"
    >

    <Button
        android:text="@string/ethan_bradberry"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:id="@+id/button_ethanBradberry"
        />

    <Button
        android:text="@string/shut_the_fuck_up"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:id="@+id/button_stfu"
        />

    <Button
        android:text="@string/HaHa"
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:id="@+id/button_haha"
        />

</LinearLayout>

<!-- row 2 -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="1"
    >

    <Button
        android:text="@string/oh_now_i_get_it"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_ohNowIGetIt"
        />

    <Button
        android:text="@string/what_the_fuck"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_whatTheFuck"
        />

    <Button
        android:text="@string/lying"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_whyTheFuckULyin"
        />

</LinearLayout>

<!-- row 3 -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="1"
    >

    <Button
        android:text="@string/why_you_haff_be_mad"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_whyYouHeffBeMad"
        />

    <Button
        android:text="@string/nigga_you_gay"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_niggaYouGay"
        />

    <Button
        android:text="@string/hit_marker"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_hitMarker"
        />

</LinearLayout>

<!-- row 4 -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="1"
    >

    <Button
        android:text="@string/its_a_trap"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_itsATrap"
    />

    <Button
        android:text="@string/shut_up_and_take_my_money"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_shutUpAndTakeMyMoney"
        />

    <Button
        android:text="@string/_smoke_weed"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_smokeWeedEveryDay"
        />

</LinearLayout>

<!-- row 5 -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="1"
    >

    <Button
        android:text="@string/stop"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_stop"
        />

    <Button
        android:text="@string/wow"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_wow"
        />

    <Button
        android:text="@string/twenty_one"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_twentyOne"
        />

</LinearLayout>

<!-- row 6 -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="1"
    >

    <Button
        android:text="@string/Surprise_Mother_fucker"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_surpriseMotherFucker"
        />

    <Button
        android:text="@string/another_one"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_anotherOne"
        />

    <Button
        android:text="@string/damn"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_daaamn"
        />

</LinearLayout>

<!-- row 7 -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="1"
    >

    <Button
        android:text="@string/hoopla"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_hoopla"
        />

    <Button
        android:text="@string/dontGetIt"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_i_dont_get_it"
        />

    <Button
        android:text="@string/dontNeedIt"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_i_dont_need_it"
        />

</LinearLayout>

<!-- row 8 -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="1"
    >

    <Button
        android:text="@string/myLeg"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_my_leg"
        />

    <Button
        android:text="@string/niggaHush"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_nigga_hush"
        />

    <Button
        android:text="@string/soiledIt"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_soiled_it"
        />

</LinearLayout>

<!-- row 9 -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="1"
    >

<Button
    android:text="@string/LoadOfBarnacles"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:id="@+id/button_loadOfBarnacles"
    />

<Button
    android:text="@string/tight"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:id="@+id/button_tight"
    />

<Button
    android:text="@string/wereWaiting"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:id="@+id/button_wereWaiting"
    />

</LinearLayout>

<!-- Row 10 -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="1"
    >

    <Button
        android:text="@string/pinhead"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_pinhead"
        />

    <Button
        android:text="@string/okaaay"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_okay"
        />

    <Button
        android:text="@string/yeaaah"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_yeaaah"
        />

</LinearLayout>

<!-- Row 11 -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:orientation="horizontal"
    android:layout_weight="1"
    >

    <Button
        android:text="@string/whaaat"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_whaaat"
        />

    <Button
        android:text="New Button"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button32"
        />

    <Button
        android:text="@string/ding"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/button_ding"
        />

</LinearLayout>

<!-- Ad -->
<com.google.android.gms.ads.AdView
    android:layout_weight="1"
    android:layout_gravity="center_horizontal"
    ads:adSize="BANNER"
    ads:adUnitId="@string/banner_ad_unit_id"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/adView"
    >

</com.google.android.gms.ads.AdView>

1 个答案:

答案 0 :(得分:1)

更改父级线性布局的android:layout_height,其垂直方向为match_parent,以使其高度与其父级相同。将android:layout_height的{​​{1}}更改为AdView,以便权重显示效果。

相关问题