开发者

Button in Relativelayout was stretched

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.


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.

<Button
   android:id  ="@+id/testButton"
   android:text="Testing"
   android:layout_width ="wrap_content"
   android:layout_height="wrap_content"
   android:layout_alignParentBottom="true"
   android:layout_alignParentRight ="true"  /> 

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!

   <LinearLayout
      android:orientation  ="horizontal"
      android:layout_width ="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight ="true">

      <Button
         android:id  ="@+id/testButton"
         android:text="Testing"
         android:layout_width ="wrap_content"
         android:layout_height="wrap_content"  />

   </LinearLayout>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜