Android 相对长度内的按钮大小和填充

Android 相对长度内的按钮大小和填充,android,android-layout,Android,Android Layout,我正在尝试创建一个类似于谷歌音乐应用程序的Heading+按钮,例如,在左侧有一个“Songs”标题,然后在右侧有一个带有文本“X more”的按钮 我已经为TextView和按钮使用了RelativeLayout 我的问题是,按钮占用了包含文本的版面的大小,高度完全错误,填充似乎没有任何作用 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_widt

我正在尝试创建一个类似于谷歌音乐应用程序的Heading+按钮,例如,在左侧有一个“Songs”标题,然后在右侧有一个带有文本“X more”的按钮

我已经为TextView和按钮使用了RelativeLayout

我的问题是,按钮占用了包含文本的版面的大小,高度完全错误,填充似乎没有任何作用

 <ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        [REMOVED for clarity]

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@color/list_foreground"
            android:orientation="vertical" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:padding="10dp"
                android:text="@string/photos"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <Button
                android:id="@+id/photo_button"
                style="?android:attr/buttonStyleSmall"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:background="@color/actionbar_background"
                android:padding="10dp"
                android:text="test" />
        </RelativeLayout>

[为清晰起见,已删除]

我做错了什么?

RelativeLayouts的设计目的是让孩子们在布局中彼此“相对”。换句话说,如果你想要文本视图右边的按钮,你需要告诉它

因为您是相对于父对象左/右对齐的,所以看起来情况“有点”正常

根据您的需要,线性布局可能会更好。线性布局使用“方向”,而不是相对性布局


您应该查看一些教程(如下面的:),但最终您可能会先将按钮放在文本视图中,然后再放在文本视图中,以便文本视图的内容能够适当地包装

为了获得与音乐应用程序相同的效果,我最终使用了RelativeLayout,但我没有使用按钮,而是使用了另一个TextView,这给人的印象是它是一个按钮,但它给了我更大的范围来格式化背景等。我想只需在代码中设置一个OnClickListener

         <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content" 
            android:id="@+id/photo_title">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentLeft="true"
                android:layout_alignParentTop="true"
                android:layout_marginLeft="10dp"
                android:text="@string/photos"
                android:textAppearance="?android:attr/textAppearanceLarge" />

            <TextView
                android:id="@+id/more_photo_text"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentRight="true"
                android:layout_centerVertical="true"
                android:layout_marginRight="10dp"
                android:background="@color/actionbar_background"
                android:paddingLeft="5dp"
                android:paddingRight="5dp"
                android:text="10 MORE"
                android:textColor="@color/button_text"
                android:textSize="12sp" />
        </RelativeLayout>