LinearLayout忽略高度

时间:2014-04-01 03:19:23

标签: android android-layout android-linearlayout

我有一个DrawerLayout (main_activity_drawer)LinearLayout (main_activity_drawer_container)(用作菜单)和一个LinearLayout (show info)

问题是Android忽略了第三个LinearLayout 高度。我为测试设置了#CDCDCD背景。我如何设置此LinearLayout的高度以及为什么android忽略高度?

我所拥有的(图片链接)

  

enter image description here

活动布局(XML)

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

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_activity_drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/gmap"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"/>

    <LinearLayout
        android:id="@+id/main_activity_details_container"
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:gravity="bottom"
        android:paddingTop="4dp"
        android:background="#CDCDCD">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="What's Up!"
            android:textColor="#000000"/>

    </LinearLayout>

    <LinearLayout
        android:id="@+id/main_activity_drawer_container"
        android:layout_width="260dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:orientation="vertical"
        android:divider="@android:color/transparent"
        android:background="@drawable/menu_background_bitmap">

        <include layout="@layout/main_activity_menu"/>

    </LinearLayout>

</android.support.v4.widget.DrawerLayout>

2 个答案:

答案 0 :(得分:0)

我认为问题可能出在您使用它的片段

android:layout_width="match_parent"
android:layout_height="match_parent"

这可能会占用更多的空间,这就是为什么高度会被忽略 尝试使用重量概念。

答案 1 :(得分:0)

尝试将linearlayout放在片段上方。这肯定会为线性布局提供一些空间。

您是否在模拟器上测试代码?如果是,那么尝试在设备上运行代码,UI可能与模拟器上的代码完全不同(有时)。

否则使用砝码是您的最佳选择。

相关问题