我正在努力解决这个问题,但我找不到任何可以帮助我的事情。
我有这个布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="8dp">
<LinearLayout
android:id="@+id/list_lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/profile_layout"
android:layout_marginTop="8dp"
android:background="@drawable/border"
android:orientation="vertical"
android:padding="8dp"
android:weightSum="1">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@id/list_lv"
android:layout_centerHorizontal="true"
android:background="@android:color/darker_gray" />
</RelativeLayout>
我想在listview下面显示一个片段。在代码中它是这样的(代码为ListActivity
:
getFragmentManager().beginTransaction().add(R.id.container, new BottomMenuFragment()).commit();
// Populate lisview and set adapter
但是当我运行应用时,片段没有显示,我认为问题在于android:layout_height="wrap_content"
ListView
的属性list_lv
。但我不知道如何解决它。以下是列表中包含多个数据的屏幕截图:
并且项目很少:
答案 0 :(得分:1)
尝试使用此xml布局基本上可以帮助您:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="10"
android:orientation="vertical"
android:layout_margin="8dp">
<LinearLayout
android:id="@+id/list_lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/profile_layout"
android:layout_marginTop="8dp"
android:background="@drawable/border"
android:orientation="vertical"
android:padding="8dp"
android:layout_weight="8">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<FrameLayout
android:layout_weight="2"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_below="@id/list_lv"
android:layout_centerHorizontal="true"
android:background="@android:color/darker_gray" />
</LinearLayout>
答案 1 :(得分:1)
将listview放在framelayout上方。删除android:layout_below =&#34; @ id / list_lv&#34;来自FrameLayout并添加android:layout_above =&#34; @ id / container&#34;到LinearLayout。下面是ecode片段:
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@android:color/darker_gray" />
<LinearLayout
android:id="@+id/list_lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/profile_layout"
android:layout_above="@id/container"
android:layout_marginTop="8dp"
android:background="@drawable/border"
android:orientation="vertical"
android:padding="8dp"
android:weightSum="1">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
答案 2 :(得分:0)
试试这个。当然它会解决你的问题:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<FrameLayout
android:id="@+id/list_lv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:orientation="vertical"
android:padding="8dp"
android:layout_weight="0.5">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:background="@android:color/darker_gray" /> </LinearLayout>
投票如果工作正常!