我正在尝试在 MapFragment
和简单的 TextView
之间共享我的屏幕布局高度,以这样一种方式,小的 TextView
在屏幕底部占据了它需要的所有空间,而 GoogleMap
fragment 填充了可用屏幕的其余部分。
像这样:
唯一的问题是我只能通过在 450dp
静态指定 fragment 的 android:layout_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。
因此 fragment
获得 LinearLayout 的 9/10,而 TextView
获得布局的 1/10。
关于android - 几乎填满整个屏幕的 map fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30945671/