Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何将按钮链接到图像上的特殊位置?_Android_Xml_Android Layout - Fatal编程技术网

Android 如何将按钮链接到图像上的特殊位置?

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

我在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/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的屏幕截图