我是移动应用程序的新手,而且我对布局很难。我的元素居中,但是当我放入更多文本时,它会将所有内容推向左侧。如何才能使文本向右移动而不推送其他内容?
布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<TextView
android:text="@string/status_text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:id="@+id/status_view"
android:layout_marginTop="59.0dp"
android:layout_height="70dp"
android:textSize="30sp" />
<ImageView
android:src="@drawable/circle_green"
android:layout_width="119.5dp"
android:layout_height="80dp"
android:id="@+id/status_image"
android:layout_toRightOf="@id/status_view"
android:layout_marginTop="37.3dp"
android:layout_marginLeft="15.6dp" />
<ImageView xmlns:tools="http://schemas.android.com/tools"
android:layout_width="40dp"
android:layout_height="40dp"
android:id="@+id/smoke_image"
android:src="@drawable/smoke_green"
android:layout_below="@id/status_view" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_below="@id/smoke_image"
android:id="@+id/motion_image"
android:src="@drawable/motion_green" />
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/smoke_view"
android:id="@+id/motion_view"
android:layout_toRightOf="@id/motion_image"
android:layout_marginTop="15dp"
android:text="Motion detected" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_below="@id/motion_image"
android:id="@+id/door_image"
android:src="@drawable/door_green" />
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/motion_view"
android:id="@+id/door_view"
android:layout_toRightOf="@id/door_image"
android:layout_marginTop="13dp"
android:text="Door open" />
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_below="@id/door_image"
android:id="@+id/temperature_image"
android:src="@drawable/temperature_green" />
<TextView
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/door_view"
android:id="@+id/temperature_view"
android:layout_toRightOf="@id/temperature_image"
android:layout_marginTop="11dp"
android:text="Temperature:" />
<TextView xmlns:tools="http://schemas.android.com/tools"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/smoke_view"
android:layout_toRightOf="@id/smoke_image"
android:text="Smoke detected"
android:layout_marginTop="7dp"
android:layout_alignBottom="@id/smoke_image" />
</RelativeLayout>
答案 0 :(得分:0)
将 android:gravity =“center”添加到您的文字视图中 如
<TextView
android:text="@string/status_text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:layout_width="wrap_content"
android:id="@+id/status_view"
android:layout_marginTop="59.0dp"
android:layout_height="70dp"
android:gravity="center"
android:textSize="30sp" />
编辑:
您可以使用android:drawableLeft="@drawable/image_name"