在RelativeLayout的按钮大小和填充 [英] Button size and padding within RelativeLayout

查看:129
本文介绍了在RelativeLayout的按钮大小和填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个类似于谷歌音乐应用程序,例如一个标题+按钮哪里有头在左边,然后在右侧诗经有一个按钮与文本X多。

I'm attempting to create a a Heading + button similar to the Google Music App, e.g. where there is a "Songs" Header on the Left and then on the right there is a Button with the text "X more"..

我使用的RelativeLayout为TextView的和按钮

I've using a RelativeLayout for the TextView and Button

我的问题是,按钮被占用包含文本的高度是完全错误的,并填充似乎并没有做任何布局的大小。

My problem is that the button is taking up the size of the layout that contains the text the height is all wrong and the padding doesn't seem to do anything.

 <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>

我在做什么错在这里?

What am I doing wrong here?

推荐答案

RelativeLayouts被设计为具有在布局亲属彼此的儿童。换句话说,如果你想要的按钮的TextView的权利,你需要告诉它。

RelativeLayouts are designed to have children in the layout "relative" to each other. In other words, if you want the Button to the right of the Textview, you need to tell it.

由于您是相对于父左/右对齐,看来事情是种的工作。

Because you are aligning relative to the parent LEFT / RIGHT, it appears that things are "kind of" working.

您可以用LinearLayout中更好,这取决于你的需求。 LinearLayouts使用方向不RelativeLayouts。

You may be better off with a LinearLayout, depending on your needs. LinearLayouts use "orientation" not RelativeLayouts.

您应该查看一些教程(像这样的:的http://移动。 tutsplus.com/tutorials/android/android-layout/ ),但最终你将可能把你的按钮,在第一,那么你的文本视图,以便TextView的内容会适当地包装。

You should look over some tutorials (like this one: http://mobile.tutsplus.com/tutorials/android/android-layout/) but ultimately you will probably put your button in first and then your text view so that the textview content will wrap appropriately.

这篇关于在RelativeLayout的按钮大小和填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆