Mp3播放器有乱搞按钮

时间:2014-06-15 20:34:15

标签: android xml eclipse button

我正在使用MP3播放器,我刚刚意识到我的main_activity.xml搞砸了

我有3个按钮,上一个,播放/暂停和下一个here

我只有1个声誉点,所以暂时没有图片上传。

这是XML:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:orientation="vertical"
    android:weightSum="7"
    tools:ignore="UselessParent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="6"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/bg"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:contentDescription="@string/Caratula" >
        </ImageView>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/buttons"
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:background="#FFFFFF"
        android:gravity="center"
        android:orientation="horizontal"
        android:weightSum="5" >

        <Button
            android:id="@+id/btnPrevious"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:layout_margin="5dp"
            android:background="@drawable/btnprevious"
            android:onClick="click" />

        <View
            android:layout_width="0dip"
            android:layout_height="0dip" />

        <Button                          
            android:id="@+id/btnPlay"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_margin="5dp"
            android:background="@drawable/play"
            android:onClick="click"  />



        <View
            android:layout_width="0dip"
            android:layout_height="0dip" />

        <Button
            android:id="@+id/btnNext"
            android:layout_width="0dip"
            android:layout_height="fill_parent"
            android:layout_margin="5dp"
            android:background="@drawable/next"
            android:onClick="click" />
    </LinearLayout>
</LinearLayout>

我会在这里感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我不确定您希望如何布置按钮,但请尝试使用包含按钮的LinearLayout ...

<LinearLayout
    android:id="@+id/buttons"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:background="#FFFFFF"
    android:gravity="center"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/btnPrevious"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_margin="5dp"
        android:background="@drawable/btnprevious"
        android:onClick="click" />

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" />

    <Button                          
        android:id="@+id/btnPlay"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_margin="5dp"
        android:background="@drawable/play"
        android:onClick="click"  />

    <View
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1" />

    <Button
        android:id="@+id/btnNext"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:layout_margin="5dp"
        android:background="@drawable/next"
        android:onClick="click" />
</LinearLayout>

您可以删除android:weightSum属性 - 它是可选的,总权重总和将计算为{{小部件的所有android:layout_weight属性的总和1}}。使用上述方法,每个LinearLayoutButton将分摊View宽度的五分之一。