【问题标题】:How to center linear layout inside maps fragment in android?如何在android中的地图片段内居中线性布局?
【发布时间】:2018-08-11 01:35:40
【问题描述】:

我有地图的片段,里面有一个线性布局。

我试过了:android:gravity="center",但没用。

我也在 xml 中搜索了“布局”和“中心”的关键字,但没有找到合适的解决方案。

我该如何解决?

这是代码:

<RelativeLayout 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:background="@color/common_google_signin_btn_text_light_pressed"
    tools:context="com.dji.GSDemo.GoogleMap.FlightActivityUser">

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/map_flight_user"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentStart="true"
        android:layout_below="@+id/flight_user_toolbar"
        tools:context="com.dji.GSDemo.GoogleMap.FlightActivityUser" >


        <LinearLayout
            android:id="@+id/ratingLayout"
            android:layout_width="wrap_content"
            android:orientation="vertical"
            android:gravity="center"
            android:background="@color/colorPrimary"
            android:layout_height="wrap_content"
            android:visibility="visible">

            <TextView
                android:id="@+id/textView2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="10dp"
                android:gravity="center_horizontal"
                android:text="How was your flight?"
                android:textSize="20sp"
                android:textStyle="italic" />

        </LinearLayout>

    </fragment>

</RelativeLayout>

谢谢

【问题讨论】:

  • 目前的输出是什么

标签: android android-fragments android-linearlayout centering


【解决方案1】:

gravity 属性会影响布局内的内容,要对齐布局本身,您应该使用 layout_gravity

【讨论】:

  • 谢谢它的工作。在尝试编写 layout_ 并自动填充它之前我没有找到这个选项......只是完整的字符串导致它编译
猜你喜欢
  • 1970-01-01
  • 2013-08-05
  • 1970-01-01
  • 2012-12-17
  • 2018-02-26
  • 2012-11-08
  • 2017-09-30
  • 1970-01-01
相关资源
最近更新 更多