2015-08-18 9 views
-1

У меня есть <fragment> для деятельности карты в моем приложении для Android. Это расположение:Android: Фрагмент занимает весь экран

<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> 

Однако, когда приложение работает, он потребляет весь экран и весь экран показывает карту и отображается запивая кнопку.

This is how it is displayed

Однако, когда я проектирования приложения на этапе компоновки, он показывает правильное форматирование.

Proper Format

Помощь ценится. Благодарю.

+0

Я вижу сжатую зеленую кнопку в эмуляторе фото – Dreo

+0

Да я не хочу его сжимает. Как исправить разрешение? –

ответ

0

Я использовал плавающую кнопку для лучшего и внедрения современных материалов, который удаляет все виды вопросов.

<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" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/map" 
     tools:context=".MapsActivity" 
     android:name="com.google.android.gms.maps.SupportMapFragment" 

     android:layout_alignParentTop="true"> 
     <Button 
      android:id="@+id/button_request" 
      android:text="Request Pickup" 
      android:textColor="#FFFFFF" 
      android:textSize="24sp" 
      android:layout_gravity="center_horizontal" 

      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_margin="13dp" 
      android:background="@drawable/map_button"> 

     </Button> 
     <android.support.design.widget.FloatingActionButton 
      android:id="@+id/fab" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="16dp" 
      android:clickable="true" 
      android:src="@drawable/add" 
      app:backgroundTint="#000000" 
      android:layout_gravity="bottom|end" 
      app:layout_anchorGravity="right|end"/> 

    </fragment> 
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> 
0

сделать ваш макет LinearLayout и назначить веса к нему. Что-то вроде этого.

<LinearLayout> 
    <LinearLayout 
     android:layout_weight="0.8" 
      > 
     <Fragment> 
     </fragment> 
    </LinearLayout> 
    <LinearLayout 
     android:layout_weight="0.2" 
    > 
    <Button></Button> 
    </LinearLayout> 
</LinearLayout> 
0

Так набор высоты фрагмента для wrap_content, установить выравнивание родителя верхнего и соответствует нижней части фрагмента с верхней части ImageView использованияКонтактная android:layout_above

<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> 

Update:

Краш Вход:

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)

UPDATE: Это должно работать

<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> 
+0

Приложение терпит крах. –

+0

Опубликовать ошибку журнала. – Dreo

+0

'Процесс: abhishekdey.ecosquare, PID: 3107 java.lang.IllegalStateException: Круговые зависимости не может существовать в RelativeLayout в android.widget.RelativeLayout $ DependencyGraph.getSortedViews (RelativeLayout.java:1701)' –

Смежные вопросы