RelativeLayout wird höher als die Bildschirmhöhe

H

hs1

Fortgeschrittenes Mitglied
8
Hallo Leute,

ich habe folgendes Problem, bei dem ich ziemlich auf dem Schlauch stehe und auf Eure Hilfe hoffe:

Ich arbeite in meiner App mit einer Activity und Fragmenten, welche dann entsprechend eingefügt werden. In einem Fragment hat der User die Möglichkeit ein Bild, welches er zuvor gemacht hat, zu bearbeiten.
In diesem Fragment wird auf der linken Seite ein LinearLayout mit Zeichenwerkzeugen angezeigt. Unten wird ein LinearLayout mit einer Farbauswahl angezeigt. Den restlichen Platz belegt ein ImageView.

Nun habe ich das Problem, dass das Bild in der Höhe abgeschnitten wird. Es sieht für mich so aus, als würde das Bild um die Höhe der Toolbar abgeschnitten werden. Ich habe das ImageView mal auf eine feste Größe gesetzt (500 x 500), dann wird es komplett angezeigt. Es scheint meiner Meinung nach irgendwie am match_parent zu liegen.


XML-Code der Activitiy:

Code:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
                                        xmlns:app="http://schemas.android.com/apk/res-auto"
                                        xmlns:tools="http://schemas.android.com/tools"
                                        android:layout_width="match_parent"
                                        android:layout_height="match_parent"
                                        tools:context="de.test.MainActivity"
                                        android:id="@+id/main_drawer_layout">


    <!-- This LinearLayout represents the contents of the screen  -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <!-- The ActionBar displayed at the top -->
        <android.support.v7.widget.Toolbar
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/main_toolbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:fitsSystemWindows="true"
            android:minHeight="?attr/actionBarSize"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            android:background="?attr/colorPrimaryDark">
        </android.support.v7.widget.Toolbar>

        <!-- The main content view where fragments are loaded -->
        <FrameLayout
            android:id="@+id/main_frame_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </LinearLayout>


    <!-- The navigation drawer that comes from the left -->
    <!-- Note that `android:layout_gravity` needs to be set to 'start' -->
    <!-- app:itemBackground="@drawable/drawer_item_background"-->
    <android.support.design.widget.NavigationView
        android:id="@+id/main_navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white"
        app:itemBackground="@android:color/white"
        app:headerLayout="@layout/main_navigation_view_header"
        app:menu="@menu/main_menu">
    </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>


XML-Code des betroffenen Fragments:

Code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/background_zeichnen"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/zeichnen_frame_layout"
        android:layout_toRightOf="@id/zeichnen_tools_bar"
        android:layout_above="@id/zeichnen_color_bar"
        android:layout_height="match_parent"
        android:layout_width="match_parent">

        <ImageView
            android:id="@+id/zeichnen_image_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="fitXY" />
    </FrameLayout>

    <LinearLayout
        android:id="@+id/zeichnen_tools_bar"
        android:layout_alignParentLeft="true"
        android:layout_width="50dp"
        android:layout_height="match_parent"
        android:background="@color/background_zeichnen"
        android:visibility="visible"
        android:orientation="vertical">

        <include
            layout="@layout/zeichnen_werkzeugauswahl"/>
    </LinearLayout>


    <LinearLayout
        android:id="@+id/zeichnen_color_bar"
        android:layout_toRightOf="@id/zeichnen_tools_bar"
        android:layout_alignParentBottom="true"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/background_zeichnen"
        android:orientation="vertical">
       
          <include layout="@layout/zeichnen_farbauswahl" />
    </LinearLayout>
</RelativeLayout>


Gruß hs1

bild.png

2018-10-04 07_43_22-.jpg
 
Hi also ich würde eher sagen das es an dem scale typ liegt und nicht match_parent

Versuche mal fitCenter statt fitXY.
Mit fitXY wird es eigentlich nicht scaliert, also an der Grösse des ImageView angepasst.
 
Das Problem ist das du sagst die ImageView soll above color Bar sein, aber gleichzeitig sagst du sie soll so groß sein wie der parent also das relative layout. damit ist sie zu groß für den Platz der da ist.
Du müsstest da mit den Layouts anders rumspielen. Schau dir zum Beispiel mal FlexBox an aus der support lib. Es müsste aber auch Linear sein.

ein horizontales linearLayout mit der tools_bar und einem layout2
layout2 ist ein vertikales LinearLayout mit der ImageView (bzw dem FrameLayout wenn du magst) und der color_bar.
Du arbeitest dann jeweils mit layout_weight um zu definieren, dass die bars die fixe größe haben sollen und dein FrameLayout gestretcht werden soll auf die passende Größe.
LinearLayout.LayoutParams  |  Android Developers
 
Danke! Ich hab's jetzt mit einem ConstraintLayout umgesetzt. Nun funktioniert es wie gewünscht :)
 

Ähnliche Themen

Manny87
  • Manny87
Antworten
11
Aufrufe
194
swa00
swa00
M
  • MikelKatzengreis
Antworten
10
Aufrufe
248
swa00
swa00
R
  • raller
Antworten
15
Aufrufe
573
DOT2010
DOT2010
Zurück
Oben Unten