Android 如何将按钮链接到图像上的特殊位置?
我在RelativeLayout上放置了按钮和imageView,这些按钮在Nexus 5上放置得非常完美: 但在Nexus One上,它的变化很大: 以下是我的xml代码:Android 如何将按钮链接到图像上的特殊位置?,android,xml,android-layout,Android,Xml,Android Layout,我在RelativeLayout上放置了按钮和imageView,这些按钮在Nexus 5上放置得非常完美: 但在Nexus One上,它的变化很大: 以下是我的xml代码: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com
<?xml version="1.0" encoding="utf-8"?>
<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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
app:srcCompat="@drawable/main_menu_top" />
<ImageView
android:id="@+id/imageView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:srcCompat="@drawable/main_menu_center"
android:layout_below="@+id/imageView6" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/imageView6">
</RelativeLayout>
<Button
android:id="@+id/top_left_button"
android:layout_width="105dp"
android:layout_height="105dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/imageView6"
android:layout_marginLeft="77dp"
android:layout_marginStart="77dp"
android:layout_marginTop="38dp"
android:background="@drawable/button_main_menu_port"
android:text="Example" />
<Button
android:id="@+id/top_right_button"
android:layout_width="105dp"
android:layout_height="105dp"
android:background="@drawable/button_main_menu_port"
android:text="Example"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="80dp"
android:layout_marginEnd="80dp"
android:layout_alignBottom="@+id/top_left_button" />
<Button
android:id="@+id/bot_left_button"
android:layout_width="105dp"
android:layout_height="105dp"
android:layout_alignLeft="@+id/top_left_button"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/top_left_button"
android:layout_marginBottom="39dp"
android:background="@drawable/button_main_menu_port"
android:text="Example" />
<Button
android:id="@+id/bot_right_button"
android:layout_width="105dp"
android:layout_height="105dp"
android:layout_alignBottom="@+id/bot_left_button"
android:layout_alignLeft="@+id/top_right_button"
android:layout_alignStart="@+id/top_right_button"
android:background="@drawable/button_main_menu_port"
android:lines="2"
android:maxLines="2"
android:minLines="2"
android:text="Example" />
</RelativeLayout>
</LinearLayout>
但是,这些按钮需要位于该图像中菱形的位置。您已经使用了按钮的
固定布局宽度和高度,并且还使用了固定布局边距。由于Nexus-Five
和Nexus-One
的分辨率不同,固定值会导致问题
解决方案:
您可以将LinearLayout
与属性android:weightSum
一起使用,并将android:layou weight
用于按钮,而不是固定的width
和height
你能发布一张你预期结果的图片吗?请查看分辨率为Nexus 5的屏幕截图