2013-10-11 58 views
0

我有一个FrameLayout可以填充屏幕和一个SurfaceView,它也可以填充屏幕。然后我有3个不同宽度的按钮。我想将这些按钮垂直排列在屏幕的右边缘,均匀分布,以便顶部按钮位于屏幕的顶部,中间位于中部,底部位于底部 - 同样,我希望垂直按钮中心彼此对齐。FrameLayout中的Android按钮布局

伪布局:

<FrameLayout layout_width="match_parent" layout_height="match_parent"> 

    <SurfaceView layout_width="match_parent" layout_height="match_parent"></SurfaceView> 

    <ToggleButton android:layout_width="45dp"></ToggleButton> 
    <ToggleButton android:layout_width="67dp"></ToggleButton> 
    <ToggleButton android:layout_width="100dp"></ToggleButton> 

</FrameLayout> 

任何帮助深表感谢和这里的什么我试图达到ASCII图片,希望它帮助!

------------------------------------------- 
|         () | 
|           | 
|           | 
|           | 
|        ( ) | 
|           | 
|           | 
|           | 
|        (  )| 
------------------------------------------- 

回答

1

试试这个

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 

     <SurfaceView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 
     </SurfaceView> 

     <RelativeLayout 
      android:gravity="center_horizontal" 
      android:layout_gravity="right" 
      android:background="#f00" 
      android:layout_width="100dp" 
      android:layout_height="wrap_content" > 

      <ToggleButton 
       android:layout_width="45dp" 
        android:layout_centerHorizontal="true" 
       android:layout_height="wrap_content" > 
      </ToggleButton> 

      <ToggleButton 
       android:layout_width="67dp" 
       android:layout_height="wrap_content" 
       android:layout_centerHorizontal="true" 
       android:layout_centerVertical="true" > 
      </ToggleButton> 

      <ToggleButton 
       android:layout_width="100dp" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentRight="true" > 
      </ToggleButton> 
     </RelativeLayout> 
    </FrameLayout> 

</RelativeLayout> 

附快照输出enter image description here

0

你可以做一个布局,然后当你在Java代码中调用它根据的宽度刚好排列按钮屏幕和按钮的宽度。把第一个按钮放在最上面,第二个按钮放在(screenheight/2-buttonheight/2)和最后一个按钮放在(screenheight-buttonheight)。

注意:尝试按照屏幕大小排列按钮,而不是根据dp或sp计算,因为屏幕大小可能会有所不同,这会弄乱整个事情。

好运

1

试试这个

<FrameLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <SurfaceView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" > 
    </SurfaceView> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" > 

     <ToggleButton 
      android:id="@+id/toggleFirst" 
      android:layout_width="45dp" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" > 
     </ToggleButton> 

     <ToggleButton 
      android:id="@+id/toggleSecond" 
      android:layout_width="67dp" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_below="@+id/toggleFirst" > 
     </ToggleButton> 

     <ToggleButton 
      android:id="@+id/toggleThird" 
      android:layout_width="100dp" 
      android:layout_height="wrap_content" 
      android:layout_alignParentRight="true" 
      android:layout_below="@+id/toggleSecond" > 
     </ToggleButton> 
    </RelativeLayout> 
</FrameLayout>