相对布局中的按钮被拉伸
基本上我想在这个相对布局中添加一个 textView 、 spinner 和一个按钮。看起来像:
---- TextView----
-----spinner----
------------button--
问题是右下角的按钮被拉伸,按钮的高度可以容纳所有其余空间。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/surveyLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:layout_alignParentTop="true"
android:text="@string/selectSurvey"
android:textColor="@android:color/darker_gray"
android:id="@+id/hasSurveyLabel"
/>
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/surveySpinner"
android:layout_below="@+id/hasSurveyLabel"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:id="@+id/startButton"
android:text="@string/start"
**android:layout_below="@+id/surveySpinner"**
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:paddingTop="10dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
/>
看起来是因为layout_below的原因,当我们使用layout_below时,spinner下面的按钮,它必须在它的正下方,没有空间,除非你定义它。
我们该如何解决这个问题?
我期望的是,将按钮放在微调器下方和屏幕底部。
我已经为此苦苦挣扎好几天了,有什么帮助吗?谢谢。
Basically I want to add a textView , spinner and a button in this relativelayout. Looks like:
---- TextView----
-----spinner----
------------button--
The problem is that button at bottom right side is stretched, the button height stands all the rest of space.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/surveyLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginTop="20dp"
android:layout_alignParentTop="true"
android:text="@string/selectSurvey"
android:textColor="@android:color/darker_gray"
android:id="@+id/hasSurveyLabel"
/>
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/surveySpinner"
android:layout_below="@+id/hasSurveyLabel"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:id="@+id/startButton"
android:text="@string/start"
**android:layout_below="@+id/surveySpinner"**
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:paddingTop="10dp"
android:paddingLeft="30dp"
android:paddingRight="30dp"
/>
Looks like it is because of layout_below, when we use layout_below, the button below spinner, it has to be just below it, no space unless you define it.
How can we solve this problem?
What I am expecting is, put button below spinner, and at the bottom of screen.
I have been struggling on this for days, any help? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我会删除对微调器的引用,并将其放在右下角。我有类似的屏幕布局,以下按钮设置适合我。
或者,我所看到的是将其包装在放置在底部的 LinearLayout 中。但对我来说,分层似乎是不必要的。希望这有帮助!
I would remove the reference to the spinner and just place it at the bottom right. I have a similar screen layout and the following button settings work for me.
Alternatively what I've seen done it to wrap in a LinearLayout that is placed at the bottom. But the layering seems unneeded to me. Hope this helps!
只是高度被拉长了吗?如果是这样,我会删除
android:layout_alignParentBottom="true"
并只让它引用 Spinner 并将其对齐到右侧...Is only the height stretched? If so, I would remove
android:layout_alignParentBottom="true"
and only let it reference the Spinner and align it to the right side...