2017-05-28 135 views
-1

我刚开始使用android开发。我只需要一个带有一些按钮的屏幕,它可以联系网络服务器,在那里触发一个动作,但我甚至没有那么远。Android布局xml“按钮堆叠”(新手)

当我向布局添加按钮时,即使它们很好地靠在一边,它们最终会在ontop上相互对齐,最后在ontop上创建按钮。

此外,我改变了颜色,但它似乎并没有被移动到模拟器中。

这是一个新鲜的设计(第二次尝试),我不明白发生了什么事情。我真的不知道什么样的文件包括:)

我意识到这是简单的东西,但我只是不知所措

谢谢 拉塞

Phone and design view

回答

0

你可能使用的FrameLayout,它只是将物体堆叠在一起,只支撑重力。

对于您的用例,您可以使用LinearLayout,RelativeLayout或ConstraintLayout。下面是使用的LinearLayout一个例子:

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

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="16dp" 
     android:text="Select releases since last candy fix" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <Button 
      android:layout_width="96dp" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="16dp" 
      android:text="Button 1" /> 

     <Button 
      android:layout_width="96dp" 
      android:layout_height="wrap_content" 
      android:layout_marginRight="16dp" 
      android:text="Button 2" /> 
    </LinearLayout> 
</LinearLayout> 

看一看不同的布局,看看哪一个更适合您的需求,ConstraintLayout将允许您扁平化布局,这是良好的性能。