2017-01-23 68 views
-2

我必须制作一个迷你项目,一个计算器。所以我开始研究这个。
当我尝试将某些按钮置于其位置(按数字顺序)时,出现问题。如何在图形xml设计屏幕中的Android Studio中移动对象?

例如,我决定每行需要3个按钮。
当我尝试移动上排时,所有按钮都会丢失其顺序。

是否有自动排序选项以禁用?

+3

你应该看一看不同的布局类。我认为一个gridview是你想包括。 https://developer.android.com/guide/topics/ui/declaring-layout.html&https://developer.android.com/guide/topics/ui/layout/gridview.html – Karl

+0

或者一个GridLayout,因为一些按钮可能会更大。 –

+1

使用网格布局..它在你需要这种布局的地方很好地工作 –

回答

-1

这是简单的只是将它们放置在LinearLayout中的水平可以在所有设备上工作,如:

<LinearLayout orientation="vertical" layout_width="wrap_content"> 
    <LinearLayout orientation="horizontal" layout_width="wrap_content"> 
     <Button>One</Button> 
     <Button>Two</Button> 
     <Button>Three</Button> 
    </LinearLayout> 
</LinearLayout> 

使用尽可能多的按钮,只要你喜欢。

+1

嵌套LinearLayouts?网格或表格布局会更好 –

+0

有很多方法可以做到这一点,我喜欢线性布局,因为它可以让我在每个按钮级别上都有力量。 取决于什么适合这个家伙...... :) –

+0

但嵌套布局是不利于表演。 –

0

以下为3个按钮的示例XML布局正如你所说

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:descendantFocusability="blocksDescendants" 
     > 


     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Close" 
      android:layout_centerHorizontal="true" 
      android:focusable="false" 
      android:focusableInTouchMode="false"/> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Next" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:focusable="false" 
      android:focusableInTouchMode="false"/> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Previous" 
      android:focusable="false" 
      android:focusableInTouchMode="false"/> 

    </RelativeLayout> 
相关问题