那么你好!Android布局 - ListView占用太多空间
我遇到了Android中的问题(我也是Android的新手)。
首先,我有2片段。 1 Fragment包含一个ListView,用于在手机上显示音乐。第二片段有一些控制。
我希望带有控件的片段停留在屏幕的底部。 ListFragment应该坚持活动的顶部。我怎样才能做到这一点?
现在,我已经决定了XML中的以下内容: activity_main.xml中:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/rain"
android:gravity="center|top"
android:orientation="vertical"
tools:context=".MainActivity" >
<!-- Playlist -->
<fragment
android:id="@+id/playlist_fragment"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_gravity="top"
android:layout_weight="6"
class="at.wireless.musicstream.fragment.PlaylistFragment" />
<!-- Separator -->
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@android:color/holo_blue_dark" />
<!-- Controls -->
<fragment
android:id="@+id/control_fragment"
android:layout_width="fill_parent"
android:layout_height="0px"
android:layout_weight="1"
class="at.wireless.musicstream.fragment.ControlFragment" />
</LinearLayout>
我用layout_weight这里,但是这不是我想要的,因为在不同的屏幕尺寸,这也将占用不同高度。但我想控制有一个 “固定” 的大小(我用DP的片段)
playlist_fragment.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center|top"
tools:context=".MainActivity" >
<ListView
android:id="@android:id/list"
android:layout_height="match_parent"
android:layout_width="match_parent" >
</ListView>
</LinearLayout>
而且我control_fragment.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:orientation="horizontal"
tools:context=".MainActivity" >
<ImageView
android:id="@+id/albumView"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_gravity="left"
android:background="@drawable/no_album_art"
android:contentDescription="Album Art" />
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView android:id="@+id/actPlayingTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textIsSelectable="false"
android:text="hier titel"
android:textColor="@android:color/white"/>
<TextView android:id="@+id/actPlayingArtist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="false"
android:textSize="12sp"
android:text="hier artist"
android:textColor="@android:color/white" />"
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:layout_marginLeft="20dp" >
<Button
android:id="@+id/rewindBtt"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="right"
android:background="@drawable/play" />
<Button
android:id="@+id/playbackBtt"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="right"
android:background="@android:color/black" />
<Button
android:id="@+id/skipBtt"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="right"
android:background="@android:color/white" />
</LinearLayout>
</LinearLayout>
ListView应该占用control_fragment离开的空间。所以可以说我有一个总屏幕高度为1000.控件占用200,然后ListView剩下800。
你可以发布可绘制的布局如何你想要的?只显示有问题的图片 – Pratik 2013-02-19 11:08:06
已添加图片和示例 – Kafioin 2013-02-19 11:31:37