【发布时间】:2018-10-26 10:44:43
【问题描述】:
我想在图像的特定位置放置文本、按钮或类似的东西。但由于设备具有不同的屏幕分辨率,文本会改变位置并且不会保留在我放置的位置。
这是对 Nexus 4 的看法:
这是 Pixel 2 XL 的视图
我该如何解决这个问题?
tuner_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/manico"
android:contentDescription="@string/chords" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="81dp"
android:layout_marginStart="81dp"
android:layout_marginTop="100dp"
android:text="D"
android:textColor="@color/black"
android:textSize="35sp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/imageView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="180dp"
android:layout_marginStart="180dp"
android:layout_marginTop="100dp"
android:text="G"
android:textColor="@color/black"
android:textSize="35sp"
app:layout_constraintStart_toEndOf="@+id/textView"
app:layout_constraintTop_toTopOf="@+id/imageView" />
</android.support.constraint.ConstraintLayout>
【问题讨论】:
-
这在Android中很正常,因为它支持different screen sizes
-
请提供您的布局
-
这里有一个有用的link ImageView 属性
-
请提供您使用过的xml和java代码。
-
这会有点棘手,因为你想把东西放在你的背景图片上。这些针脚(Idk 他们叫什么)占用多少空间以及它们从顶部/彼此之间有多少空间等是否有任何规则?如果是这样,您可以使用
ConstraintLayout并将Guidelines设置为某些值,例如到每排引脚的中间,然后在此基础上放置textviews。
标签: java android android-layout