我的Android应用中有一个<fragment>
地图活动。这是布局:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="481dp" android:id="@+id/map" tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/round"
android:layout_below="@+id/map" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:layout_alignParentBottom="true"
android:layout_alignTop="@+id/button"
android:layout_alignStart="@+id/button"
android:layout_alignEnd="@+id/button"
android:src="@drawable/tick"/>
</RelativeLayout>
然而,当应用程序运行时,它正在消耗整个屏幕,整个屏幕显示地图并显示挤压按钮。
但是,当我在布局阶段设计应用程序时,它会显示正确的格式。
帮助表示赞赏。感谢。
答案 0 :(得分:0)
试试这个布局:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<fragment
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="8"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="2">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/round"
android:layout_below="@+id/map" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:id="@+id/imageView2"
android:layout_alignParentBottom="true"
android:layout_alignTop="@+id/button"
android:layout_alignStart="@+id/button"
android:layout_alignEnd="@+id/button"
android:src="@drawable/tick" />
</RelativeLayout>
</LinearLayout>
答案 1 :(得分:0)
制作您的布局LinearLayout并为其指定权重。这样的事情。
<LinearLayout>
<LinearLayout
android:layout_weight="0.8"
>
<Fragment>
</fragment>
</LinearLayout>
<LinearLayout
android:layout_weight="0.2"
>
<Button></Button>
</LinearLayout>
</LinearLayout>
答案 2 :(得分:0)
因此,将片段高度设置为wrap_content,将align parent top设置为匹配片段的底部与使用android:layout_above
的imageview的顶部
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/map" tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_above="@+id/imageView2"
android:layout_alignParentTop="true"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="@+id/button"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@drawable/round"
android:layout_below="@+id/map" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:layout_alignParentBottom="true"
android:layout_alignTop="@+id/button"
android:layout_alignStart="@+id/button"
android:layout_alignEnd="@+id/button"
android:src="@drawable/tick"/>
</RelativeLayout>
更新
崩溃日志:
08-18 18:26:40.314 3107-3107/abhishekdey.ecosquare D/AndroidRuntime﹕ Shutting down VM
--------- beginning of crash
08-18 18:26:40.363 3107-3107/abhishekdey.ecosquare E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: abhishekdey.ecosquare, PID: 3107
java.lang.IllegalStateException: Circular dependencies cannot exist in RelativeLayout
at android.widget.RelativeLayout$DependencyGraph.getSortedViews(RelativeLayout.java:1701)
at android.widget.RelativeLayout.sortChildren(RelativeLayout.java:381)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:389)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1436)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:722)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:613)
at android.view.View.measure(View.java:17430)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5463)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2560)
at android.view.View.measure(View.java:17430)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2001)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1166)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1372)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
更新: 这应该工作
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="wrap_content" android:id="@+id/map" tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_above="@+id/bottom_view"
android:layout_alignParentTop="true"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id = "@+id/bottom_view"
android:layout_alignParentBottom="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_centerInParent="true"
android:id="@+id/button"
android:background="@drawable/round" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:src="@drawable/tick"/>
</RelativeLayout>
</RelativeLayout>