视图在相对布局中与另一个视图一起移动?

时间:2013-10-14 14:45:52

标签: android xml

我有以下XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ce6517"
tools:context=".MainActivity" >

<RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/relative" >

<ImageView android:id="@+id/upload_IV"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/upload" />

<TextView android:id="@+id/upload_TV"
    android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Upload" android:layout_below="@+id/upload_IV"/>


<ImageView android:id="@+id/settings_IV"
    android:layout_marginLeft="150dp"
    android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/upload" android:layout_toRightOf="@+id/upload_IV"/>

<TextView
    android:id="@+id/settings_TV"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/settings_IV"
    android:layout_toRightOf="@+id/upload_TV"
    android:text="Settings" />

</RelativeLayout>

看起来像这样:

enter image description here

问题:如何在第二个图标下方定位名为“设置”的TextView?因此,如果我在第二个图标上留出更多余量,文本会随之移动吗?这可能吗?

1 个答案:

答案 0 :(得分:1)

<TextView
    android:id="@+id/settings_TV"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/settings_IV"
    android:layout_alignLeft="@+id/settings_IV"
    android:text="Settings" />

此外,不需要第二个RelativeLayout,您可以将视图保留为根视图的子视图。

相关问题