What is the best way to create this Layout in Android? -


i have been struggling hours layout work.

enter image description here

here code:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     android:paddingbottom="@dimen/activity_vertical_margin"     android:orientation="horizontal"     tools:context=".mainpreviewactivity">      <fragment         android:name="com.apps.foo.cleanpreviewfragment"         android:id="@+id/clean_preview_fragment"         android:layout_weight="0.5"         android:layout_width="0dp"         android:layout_height="match_parent">     </fragment>      <fragment         android:name="com.apps.foo.pointop.dirtypreviewfragment"         android:id="@+id/filters_fragment"         android:layout_weight="0.5"         android:layout_width="0dp"         android:layout_height="match_parent">     </fragment>      <fragment         android:name="com.apps.foo.pointop.processedpreviewfragment"         android:id="@+id/processed_preview_fragment"         android:layout_weight="1"         android:layout_width="0dp"         android:layout_height="match_parent">     </fragment>  </linearlayout> 

every fragment simple relativelayout (all have same view):

<relativelayout     xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     tools:context="com.apps.<whatever fragment name is>"> </relativelayout> 

now want make work this:

  • 1) no nested layout_weight

  • 2) no nesting @ (for example nest 2 first fragments etc etc)

  • 3) not using code programmatically after view has rendered.

in opinion cleanest readable way of doing this, set orientation of fragment 1 , fragment 2 horizontal, , fragment 3 vertical, not work.

i've checked this answer, guy, uses layout_weight relativelayout. relativelayouts ignore weights not work.

any appreciated?

you can add dummy view of 0dp width , height in center of layout using relativelayout, , position fragments accordingly:

<relativelayout    ... >    <view     android:id="@+id/center_anchor"     android:layout_width="0dp"     android:layout_height="0dp"     android:layout_centerinparent="true" />    <fragment     android:layout_toleftof="@id/center_anchor"     android:layout_above="@id/center_anchor"     ... />    <fragment     android:toleftof="@id/center_anchor"     android:layout_below="@id/center_anchor"     ... />    <fragment     android:torightof="@id/center_anchor"     ... />  </relativelayout> 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -