Android 使用背景图像定位元素
我需要你的帮助。Android 使用背景图像定位元素,android,Android,我需要你的帮助。 我有一个图像(EG),我想把我的相对布局放在中间。 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:fbutton="http://schemas.android.com/tools" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="
我有一个图像(EG),我想把我的相对布局放在中间。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fbutton="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@null">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="12dp"
android:paddingLeft="29dp"
android:paddingRight="35dp"
android:paddingTop="70dp"
android:paddingBottom="70dp"
android:background="@drawable/phone2">
问题是当屏幕大小改变时,relativelayout太大/太小。如何使relativelayout始终处于屏幕大小的中间?使用
android:gravity="center"
比如:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fbutton="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center"
android:background="@null">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="12dp"
android:paddingLeft="29dp"
android:paddingRight="35dp"
android:paddingTop="70dp"
android:paddingBottom="70dp"
android:background="@drawable/phone2"/>
</LinearLayout>
<代码> > P>这是你的平铺(没有布局嵌套!)布局,中间有一个TeTVIEW显示一些文本。
您可以使用ImagView或具有一些复合绘图功能的TextView来混合文本和图片
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fbutton="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/tv"
>
<TextView
android:id="@+id/txtContents"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:layout_centerInParent="true"
android:text="Some text contents here"
/>
</RelativeLayout>
android:layout\u centerInParent=“true”
将视图置于水平和垂直中心
您可能希望使用android:layout\u centerVertical=“true”
或android:layout\u centerHorizontal=“true”
将居中限制为仅一种大小。这是因为您为版面提供的填充量会产生问题。请将图像视图与android:src=“@drawable/phone”一起使用,不是相对性布局。为什么有两个嵌套布局?我知道,但我不知道如何在不使用pxmake linearlayout作为匹配父宽度和高度的情况下将元素放置在图像顶部谢谢,但是如何把元素放在中间呢?我想你问:<代码>如何使相对论总是在屏幕大小的范围内?< /代码>无论如何……只需删除centerInParent
属性,并使用填充和/或边距和/或其他相对对齐属性(即:alignParentLeft
)