使用布局,并使布局中的ImageView和两个按钮的子级。
例使用的RelativeLayout:
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:src="@drawable/image"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:alpha="0.5"
android:text="Button 1"/>
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/button1"
android:alpha="0.5"
android:text="Button 2"/>
你可以定位你的按钮使用的Android更好:layout_marginTop和android:layout_marginLeft属性。
关键零部件在这里理解为:
1 /本的ImageView设置为match_parent,因此它会拉伸填充RelativeLayout的。
2 /默认情况下,子视图位于RelativeLayouts的左上角,这就是为什么button1出现在那里。
3/Button2使用RelativeLayout属性layout_toRightOf定位在button1的右侧。其垂直位置仍然设置为默认 - 顶部。