代码之家  ›  专栏  ›  技术社区  ›  jonb

如何在android中集中地图片段内部的线性布局?

  •  0
  • jonb  · 技术社区  · 7 年前

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

    我尝试过: android:gravity="center" 但它没有起作用。

    我还在xml中搜索了关键字“layout”和“center”,但没有找到合适的解决方案。

    我如何解决它?

    代码如下:

    <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>
    

    谢谢

    1 回复  |  直到 7 年前
        1
  •  1
  •   javier Cuervas    7 年前

    重力特性影响布局内的内容,要对齐布局本身,应使用layout\u gravity