【问题标题】:android layout fragment and normal layoutandroid布局片段和普通布局
【发布时间】:2013-02-07 08:40:44
【问题描述】:

你好,这个想法是编写一个 Activity,将 google map api v2 显示为片段,并在底部有两个按钮用于处理服务并在地图上生成标记。

现在的问题是是否可以将地图片段放入定义和处理按钮的正常布局中,还是我必须将按钮放入另一个片段中?

目前地图覆盖整个屏幕,即使我通过 android:height 限制大小

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/DarkGrey">


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



        <LinearLayout 
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="bottom">
            <Button 
                android:id="@+id/buttonStopTracking"
                android:text="@string/btn_stop_tracking"
                android:layout_width="160dp"
                android:layout_height="60dp"
                android:textSize="20sp" 
                android:textStyle="bold" 
                />
            <Button
                android:id="@+id/buttonCreatePoI"
                android:text="@string/btn_create_PoI"
                android:layout_width="160dp"
                android:layout_height="60dp"    
                android:textSize="20sp"
                android:textStyle="bold" 
                />
        </LinearLayout>

【问题讨论】:

  • 您在 xml 的末尾错过了“”。添加它。
  • 然后将“”改为“”。
  • linkv 还可以很好地了解解决方案

标签: android google-maps android-linearlayout fragment


【解决方案1】:

我希望我的布局 xml 会对您有所帮助。

就我而言,所有按钮和文本视图都位于 谷歌地图上。 我正在使用新的 Google Maps API v2,我的 MainActivity 扩展了“android.support.v4.app.FragmentActivity”。

这是我的完整 xml;

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/RelativeLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

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

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="40sp"
        android:layout_alignParentTop="true" >

    <Button
        android:id="@+id/provider_fine"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_inactive"
        android:minWidth="160sp"
        android:onClick="useFineProvider"
        android:text="@string/use_fine_provider" />

    <Button
        android:id="@+id/provider_both"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_inactive"
        android:minWidth="160sp"
        android:onClick="useCoarseFineProviders"
        android:text="@string/use_both_providers" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/LinearLayout3"
        android:layout_width="match_parent"
        android:layout_height="40sp"
        android:layout_below="@+id/LinearLayout1" >

    <Button
        android:id="@+id/reset_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_inactive"
        android:minWidth="160sp"
        android:onClick="resetButton"
        android:text="@string/reset_button" />

    <Button
        android:id="@+id/calc_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_inactive"
        android:minWidth="160sp"
        android:onClick="calcButton"
        android:text="@string/calc_button" />

    </LinearLayout>




    <LinearLayout
        android:id="@+id/LinearLayout2"
        android:layout_width="match_parent"
        android:layout_height="95sp"
        android:orientation="vertical"
        android:layout_alignParentBottom="true" >

    <TextView
        android:id="@+id/label_latlng"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/latlng"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/latlng"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/label_address"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/address"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/address"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/secondText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="10sp" />

    <TextView
        android:id="@+id/distanceText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="10sp" />

    </LinearLayout>


</RelativeLayout>

结果画面如下; 由于我的隐私,我删除了图片上的一些文字。

【讨论】:

    【解决方案2】:
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@color/DarkGrey">
            <LinearLayout 
                android:orientation="horizontal"
                android:layout_width="fill_parent"
                android:layout_height="0dp"
                android:layout_weight="1">
    
                <fragment 
                    android:id="@+id/map"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    class="com.google.android.gms.maps.SupportMapFragment" />
            </LinearLayout>
    
    
            <LinearLayout 
                android:orientation="horizontal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="bottom">
                <Button 
                    android:id="@+id/buttonStopTracking"
                    android:text="@string/btn_stop_tracking"
                    android:layout_width="160dp"
                    android:layout_height="60dp"
                    android:textSize="20sp" 
                    android:textStyle="bold" 
                    />
                <Button
                    android:id="@+id/buttonCreatePoI"
                    android:text="@string/btn_create_PoI"
                    android:layout_width="160dp"
                    android:layout_height="60dp"    
                    android:textSize="20sp"
                    android:textStyle="bold" 
                    />
            </LinearLayout>
    </LinearLayout>
    

    应该做我猜的伎俩。

    使用 layout_weight 是诀窍。

    第一个布局的方向也是垂直的。

    【讨论】:

    • to bad 行不通。我玩了一下 android:weight 并将它的底部 LinearLayout 设置为 6 并将 android:layout_height 设置为 0dp 但地图片段仍然占据整个屏幕
    猜你喜欢
    • 2015-08-13
    • 2015-11-02
    • 2011-07-15
    • 2017-04-15
    • 1970-01-01
    • 1970-01-01
    • 2019-02-15
    • 1970-01-01
    • 2013-01-10
    相关资源
    最近更新 更多