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>