所以我想在活动中使用一个ImageView,它是一个语音泡沫,一个按钮是一个企鹅。企鹅按钮应位于右下角,而语音气泡ImageView则应位于企鹅左上方。当我将所有宽度和高度都设置为固定值时,它可以正常工作,但是一旦在另一台设备上打开它,它们的大小都会重新调整。我的问题是,我找不到任何使这些元素适应我想要的屏幕尺寸的方法。下面的代码可以在每个设备上调整其大小,但会将其大小调整为50/50,因此ImageView占据上屏幕的50%,而按钮占据下屏幕的50%。我不知道如何将它们保持在某个位置,同时仍在不同的屏幕上调整大小。欢迎任何帮助。
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="@drawable/ein_hintergrund2"
tools:context=".MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:srcCompat="@drawable/speechbubble"
android:id="@+id/klick_textView"
android:layout_marginBottom="9dp"
android:contentDescription="@string/todo"/>
<Button
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:id="@+id/start_button"
android:background="@drawable/pinguin"/> </LinearLayout>
由于有点复杂,我会根据不同的屏幕尺寸使用不同的布局。或如果是风景等。
我建议您看看this page。