1

こんにちは!

Androidで問題が発生しました(Androidも初めてです)。

まず、2つのフラグメントがあります。1フラグメントには、電話で音楽を表示するListViewが含まれています。2番目のフラグメントにはいくつかのコントロールがあります。

コントロール付きのフラグメントを画面の下部に配置したい。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を残します。

4

1 に答える 1

1

RelativeLayoutに切り替えます。これにより、コントロールを固定位置にとどめることができます。また、コントロールの高さを定義する必要があります(これを200dpに設定しました)。

<RelativeLayout 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"
tools:context=".MainActivity" >

<!-- Playlist -->
<fragment
    android:id="@+id/playlist_fragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="top"
    class="at.wireless.musicstream.fragment.PlaylistFragment"
    android:layout_above="@+id/separator"/>

<!-- Separator -->
<View
    android:id="@+id/separator"
    android:layout_width="match_parent"
    android:layout_height="2dp"
    android:layout_above="@+id/control_fragment"
    android:background="@android:color/holo_blue_dark" />

<!-- Controls -->
<fragment
    android:id="@+id/control_fragment"
    android:layout_width="fill_parent"
    android:layout_height="200dp"
    android:layout_alignParentBottom="true"
    class="at.wireless.musicstream.fragment.ControlFragment" />
    </RelativeLayout>
于 2013-02-19T11:37:10.303 に答える