【发布时间】:2015-09-05 21:08:50
【问题描述】:
我试图在MapFragment 和一个简单的TextView 之间共享我的屏幕布局的高度,这样屏幕底部的小TextView 就占据了它需要的所有空间,而GoogleMap 片段填充了可用屏幕的其余部分。
像这样:
唯一的问题是我只能通过在450dp处静态指定片段的android:layout_height来获得这样的结果,而我还没有找到动态这样做的方法,因此布局会同时适应它的landscape 模式和不同屏幕尺寸的手机。
这是我尝试做的:
<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>
这是不想要的结果:
【问题讨论】:
-
听起来好像您最适合使用
RelativeLayout。将TextView分配到屏幕底部,并将地图分配到它上方和靠近顶部的选项卡下方。然后TextView应该会根据需要向上扩展并且地图会调整。 -
为什么所有的东西都包裹在一个 ScrollView 中? :|
-
您的 cmets 解决了,谢谢。
android:layout_weight属性不起作用仅仅是因为ScrollView标签......也许你应该留下一个答案让我接受;)
标签: android android-layout android-fragments layout