android - 如何在android中的LinearLayout内左右对齐2张图片

标签 android android-layout

我想在谷歌地图下方并排显示两张图片。图片显示正常。但图像显示同一侧。我想在两张图片中间显示一些文字。

enter image description here

我想在 View 的右侧显示第二张图片,在中间显示文本。

当前代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <fragment
        android:id="@+id/map"
        class="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:background="@color/bt_white">

        <ImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_marginStart="5dp"
            android:src="@drawable/ic_menu_camera"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="match_parent">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/black"
                android:text="@string/action_settings"/>
        </LinearLayout>

        <ImageView
            android:id="@+id/imageView12"
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:gravity="right"
            android:src="@drawable/ic_menu_camera" />

    </LinearLayout>


</LinearLayout>

最佳答案

这是你的布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<fragment
    android:id="@+id/map"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/bt_white"
    android:orientation="horizontal"
    android:weightSum="3">

    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_alignParentLeft="true"
        android:layout_marginStart="5dp"
        android:src="@android:drawable/ic_menu_camera" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="First Text View"
            android:textColor="@color/black" />

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:text="Second Text view"
            android:textColor="@color/black" />
    </LinearLayout>

    <ImageView
        android:id="@+id/imageView12"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_alignParentRight="true"
        android:src="@android:drawable/ic_menu_camera" />
</RelativeLayout>
</LinearLayout>
</LinearLayout>

这是它的样子

enter image description here

关于android - 如何在android中的LinearLayout内左右对齐2张图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45918903/

相关文章:

Android UI TabActivity 问题

Android:如何为 LinearLayout 绘制边框

javascript - react native 'unexpected url'错误

android - 如何知道/配置 Xamarin Android 生成的包名称?

android - WhatsApp 在共享图像时是否使用原生图库

android - ActiveAndroid Update() 查询

java - 如何解决在 android studio 中查看预览的问题?字符串索引超出范围 : -1

android - 适用于所有 Samsung Galaxy Tabs 的应用程序,如何制作可绘制对象和布局

android - Android 8 (Oreo) 中的后台位置限制是什么?

java - gradle 同步时出错