1

我有这个标题:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="fill_parent"
android:padding="5dip">    

 <Button android:id="@+id/home"
  android:layout_width="wrap_content" android:layout_height="wrap_content"
  android:text="Home"
/>

 <Button android:id="@+id/questions"
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"
  android:text="My Questions"
 /> 

<Button android:id="@+id/questions"
 android:layout_width="wrap_content" android:layout_height="wrap_content"
 android:text="Questions"
android:layout_toRightOf="@+id/home"  />  


 <Button android:id="@+id/businesses"
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"
  android:text="Businesses"
android:layout_toRightOf="@+id/businesses"
 />  

 <Button android:id="@+id/learn"
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"
  android:text="Learn"
  android:layout_toRightOf="@+id/learn"
 />  


 <Button android:id="@+id/extra_help"
  android:layout_width="wrap_content" 
  android:layout_height="wrap_content"
  android:text="Help"
  android:layout_toRightOf="@+id/learn"
/>  
</RelativeLayout>

并且由于某种原因,按钮显示 50% 彼此叠加在一起,每个都覆盖了另一个的一半。

知道我的布局有什么问题吗?

谢谢!

4

1 回答 1

1

您正在使用相对布局,您需要管理水平和垂直对齐。比如所有的android:layout_toRightOf都是用于水平定位的,你还需要添加属性来处理垂直定位。

所有可能的属性都可以在这里找到:http: //developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html

UPDATE Seeing your comments below, it seems you just want to have one horizontal row. In that case, just make sure each is aligned to the previous one(But then why not use a linear layout?)

Check your id's though, and @+id/learn is aligned to the right of itself. Revisit that. And you also have a button right after "Home" that isn't handled at all.

于 2012-05-15T03:07:45.403 回答