Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 地图碎片几乎占据了整个屏幕_Android_Android Layout_Android Fragments_Layout - Fatal编程技术网

Android 地图碎片几乎占据了整个屏幕

Android 地图碎片几乎占据了整个屏幕,android,android-layout,android-fragments,layout,Android,Android Layout,Android Fragments,Layout,我试图在一个MapFragment和一个简单的TextView之间共享屏幕布局的高度,这样屏幕底部的小TextView就占据了它所需要的所有空间,而GoogleMap片段则占据了可用屏幕的其余部分 像这样: 唯一的问题是,我只能通过在450dp处静态指定片段的android:layou height来获得这样的结果,而我还没有找到一种方法来动态地这样做,以便布局能够适应横向模式和不同屏幕大小的手机 这就是我试图做的: <ScrollView xmlns:android="http://s

我试图在一个
MapFragment
和一个简单的
TextView
之间共享屏幕布局的高度,这样屏幕底部的小
TextView
就占据了它所需要的所有空间,而
GoogleMap
片段则占据了可用屏幕的其余部分

像这样:

唯一的问题是,我只能通过在
450dp
处静态指定片段的
android:layou height
来获得这样的结果,而我还没有找到一种方法来动态地这样做,以便布局能够适应
横向模式和不同屏幕大小的手机

这就是我试图做的:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_height="match_parent"
    android:layout_width="match_parent" tools:context="madapps.bicitourbo.DetailsFragmentTwo">

    <LinearLayout android:id="@+id/map"
        android:layout_height="wrap_content" android:layout_width="match_parent"
        android:orientation="vertical"
        android:weightSum="10">
        <!--android:paddingRight="16dp"-->
        <!--android:paddingLeft="16dp"-->

        <fragment xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/mapFrag"
            android:layout_height="0dp"
            android:layout_width="match_parent"
            android:layout_weight="9"
            android:name="com.google.android.gms.maps.MapFragment"/>

        <TextView android:id="@+id/headerTitle"
            android:gravity="center_horizontal"
            android:layout_height="0dp"
            android:layout_width="match_parent"
            android:text="Partenza da: Piazza Santo Stefano"
            android:textSize="@dimen/textSizeBig" android:textColor="@color/textLightBlack"
            android:layout_marginBottom="16dp"
            android:layout_marginTop="16dp"
            android:layout_weight="1"/>
    </LinearLayout>

</ScrollView>

这是不想要的结果:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent" tools:context="madapps.bicitourbo.DetailsFragmentTwo">

<LinearLayout android:id="@+id/map"
    android:layout_height="match_parent" android:layout_width="match_parent"
    android:orientation="vertical"
    android:weightSum="10">
    <!--android:paddingRight="16dp"-->
    <!--android:paddingLeft="16dp"-->

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/mapFrag"
        android:layout_height="0dp"
        android:layout_width="match_parent"
        android:layout_weight="9"
        android:name="com.google.android.gms.maps.MapFragment"/>

    <TextView android:id="@+id/headerTitle"
        android:gravity="center_horizontal"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:text="Partenza da: Piazza Santo Stefano"
        android:textSize="@dimen/textSizeBig" android:textColor="@color/textLightBlack"
        android:layout_marginBottom="16dp"
        android:layout_marginTop="16dp" 
        android:layout_weight="1"/>
</LinearLayout>


android:weightSum
给出了
LinearLayout
的总权重为10


因此,
片段
获得9/10的线性布局,
文本视图
获得1/10的布局。

您可以使用
RelativeLayout

    <ScrollView 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"
    tools:context="madapps.bicitourbo.DetailsFragmentTwo">

    <RelativeLayout
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <!--android:paddingRight="16dp"-->
        <!--android:paddingLeft="16dp"-->

        <TextView
            android:id="@+id/headerTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="16dp"
            android:layout_marginTop="16dp"
            android:gravity="center_horizontal"
            android:text="Partenza da: Piazza Santo Stefano"
            android:textColor="@color/textLightBlack"
            android:textSize="@dimen/textSizeBig" />

        <fragment xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/mapFrag"
            android:name="com.google.android.gms.maps.MapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_above="@id/headerTitle" />
    </RelativeLayout>

</ScrollView>


对我的问题的评论解决了这个问题

android:layou-weight
属性不起作用,只是因为将
ScrollView
作为根标记会阻止其效果。
通过将
RelativeLayout
作为根标记,weigth属性起作用,TextView应根据需要向上扩展,同时地图将进行调整

听起来好像你最适合使用
RelativeLayout
。将
TextView
分配到屏幕底部,并在顶部附近的选项卡上方和下方分配地图。然后,
TextView
应该根据需要向上展开,地图将进行调整。为什么所有内容都包装在滚动视图中|你的评论解决了这个问题,谢谢。
android:layou-weight
属性不起作用仅仅是因为
ScrollView
标记。。。也许你应该留下一个答案让我接受;)为什么要为片段指定两个属性
android:layout\u weight=9
android:layout\u weight=1
?因为它们都有自己的权重。一个是片段,一个是文本视图。我的意思是相同的片段视图。不可能为同一视图放置两次相同属性。两次相同属性是什么意思?请检查片段属性。。。您已经放置了两次属性
android:layout\u weight