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
Android 将带有图标的按钮放在顶部,每个按钮并排放置?_Android_Xml_Android Layout - Fatal编程技术网

Android 将带有图标的按钮放在顶部,每个按钮并排放置?

Android 将带有图标的按钮放在顶部,每个按钮并排放置?,android,xml,android-layout,Android,Xml,Android Layout,我试图在我的应用程序中实现以下简单活动: 到目前为止,我做到了: <?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"

我试图在我的应用程序中实现以下简单活动:

到目前为止,我做到了:

<?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"
    tools:context=".screens.MainScreen">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="427dp"
        android:gravity="center"
        android:text="@string/app_name" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="296dp"
        android:paddingLeft="@dimen/button_padding"
        android:paddingTop="@dimen/button_padding"
        android:paddingRight="@dimen/button_padding"
        android:paddingBottom="@dimen/button_padding">

        <RelativeLayout
            android:id="@+id/detect_ip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true">

            <ImageView
                android:id="@+id/play"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:srcCompat="@android:drawable/ic_media_play" />

            <TextView
                :layout_alignParentBottom="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:
                android:text="@string/retrieve" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/licence"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/detect_ip"
            android:layout_alignBottom="@+id/detect_ip"
            android:layout_marginStart="42dp"
            android:layout_marginBottom="3dp"
            android:layout_toEndOf="@+id/detect_ip"
            android:clickable="true">

            <ImageView
                android:id="@+id/gpl"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:srcCompat="@drawable/gplv3" />

            <TextView
                :layout_alignParentBottom="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:
                android:text="@string/licence" />
        </RelativeLayout>
    </RelativeLayout>

</LinearLayout>

但结果我做到了:

<?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"
    tools:context=".screens.MainScreen">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="427dp"
        android:gravity="center"
        android:text="@string/app_name" />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="296dp"
        android:paddingLeft="@dimen/button_padding"
        android:paddingTop="@dimen/button_padding"
        android:paddingRight="@dimen/button_padding"
        android:paddingBottom="@dimen/button_padding">

        <RelativeLayout
            android:id="@+id/detect_ip"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:clickable="true">

            <ImageView
                android:id="@+id/play"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:srcCompat="@android:drawable/ic_media_play" />

            <TextView
                :layout_alignParentBottom="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:
                android:text="@string/retrieve" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/licence"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/detect_ip"
            android:layout_alignBottom="@+id/detect_ip"
            android:layout_marginStart="42dp"
            android:layout_marginBottom="3dp"
            android:layout_toEndOf="@+id/detect_ip"
            android:clickable="true">

            <ImageView
                android:id="@+id/gpl"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:srcCompat="@drawable/gplv3" />

            <TextView
                :layout_alignParentBottom="true"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:
                android:text="@string/licence" />
        </RelativeLayout>
    </RelativeLayout>

</LinearLayout>


因此,我很难将图像下方的文本对齐。你知道我该怎么做吗?

你可以使用以下方法:

<TextView
    android:text="@string/app_name"

<RelativeLayout
    android:gravity="center_horizontal"
    ../>

    <RelativeLayout
        android:id="@+id/detect_ip">

        <ImageView
            android:id="@+id/play"
            android:layout_centerHorizontal="true"
            .../>

        <TextView
            android:layout_centerHorizontal="true"
            android:layout_below="@id/play"
            ../>
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/licence"
        ..>

        <ImageView
            android:layout_centerHorizontal="true"
            android:id="@+id/gpl"
            ../>

        <TextView
            android:layout_centerHorizontal="true"
            android:layout_below="@id/gpl"
            .../>

    </RelativeLayout>

</RelativeLayout>