dankito / RichTextEditor

Rich text WYSIWYG editor for Android and JavaFX
Apache License 2.0
92 stars 36 forks source link

How do I get the "required size" #45

Closed fabianscode closed 4 years ago

fabianscode commented 4 years ago

How do I get the "required size" so I can auto resize the view? Thanks in advance

dankito commented 4 years ago

What do you mean by "required size"?

Usually you just add it to your fragment / activity and set your preferred size there like this:

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="<set your size here>"
        >

        <net.dankito.richtexteditor.android.RichTextEditor
            android:id="@+id/editor"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="10"
            />

        <net.dankito.richtexteditor.android.toolbar.GroupedCommandsEditorToolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="36dp"
            android:background="?attr/colorPrimary"
            android:visibility="visible"
            />

    </LinearLayout>
fabianscode commented 4 years ago

its not that simple. Imagine a OneNote like app where you can place text items by touching on the screen. At the beginning it has a size like (100dp, 50dp) an when the text changes it shall resize the element, so that its bounds correspond to the bounds the text would need. Get what I mean?

dankito commented 4 years ago

Puh, tough question, i don't know if i can answer this as i am not so deep into Android anymore.

Is this possible in general on Android, e.g. with an EditText that automatically resizes when its content grows?

If so my first guess would be setting layout_height to wrap_content for both the editor and its containing layout.

Otherwise i think you would have to do this manually by checking if editor.computeVerticalScrollRange() is larger than height or measuredHeight (as i said i'm not so deep into it anymore, don't know which of the latter two returns the displayed height, i guess the last one).

To get informed about layout changes you may can use - just guesses - addOnLayoutChangeListener(), onSizeChanged() (overwrite it) or addHtmlChangedListener().

fabianscode commented 4 years ago

Thank you. It did not work unfortunately, but doesnt matter, since I dont need the functionality any more.