简体   繁体   English

如何在布局中独立视图

[英]How Can I independent the views in a layout

How can I move views independently from other views in a layout ? 如何独立于布局中的其他视图移动视图? For example, I want to be able to move one button up without the other moving but, currently, they are both moving. 例如,我希望能够向上移动一个按钮,而又不移动其他按钮,但是目前它们都在移动。 For more information please see the following image: 有关更多信息,请参见下图:

在此处输入图片说明

<Button
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    />

<Button
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button2"
    android:layout_alignParentBottom="true"
    android:layout_toRightOf="@+id/button"
    android:layout_toEndOf="@+id/button"
    />

<Button
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button3"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="39dp" />

<Button
    style="?android:attr/buttonStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button4"
    android:layout_alignTop="@+id/button3"
    android:layout_alignLeft="@+id/button2"
    android:layout_alignStart="@+id/button2" />

First you not posted complete xml layout file. 首先,您没有发布完整的xml布局文件。 How can some some know what layout you are using. 一些人怎么知道您正在使用什么布局。

Solution:You need to put both buttons in different layout if your are using LinearLayout or you can use Relative Layout but in Relative Layout case both buttons should not be depend on each other. 解决方案:如果您使用的是LinearLayout则需要将两个按钮放置在不同的布局中,或者可以使用“ Relative Layout但是在“ Relative Layout情况下,两个按钮不应相互依赖。

You can use a RelativeLayout to embed the components you want. 您可以使用RelativeLayout嵌入所需的组件。

 <RelativeLayout
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="10dp"
                    android:orientation="vertical"
                    android:padding="10dp">

                    <TextView
                        android:id="@+id/cardholderNameText"
                        style="@style/form_label"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginBottom="10dp"
                        android:text="@string/cardholder_name" />
  </RelativeLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM