1. Download our Official Android App: Forums for Android!

Apps Dimensions of a fragments layout in android studio

Discussion in 'Android Development' started by bravoelf, Mar 28, 2016.

  1. bravoelf

    bravoelf Lurker
    Thread Starter
    Mar 23, 2016

    Mar 23, 2016

    Ok, I'll describe my situation briefly.

    I have main_actvity.xml file which looks like this(just followed Android Devs guide):
    Code (Java):
    1. <?xml version="1.0" encoding="utf-8"?>
    2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    3.     xmlns:tools="http://schemas.android.com/tools"
    4.     android:layout_width="match_parent"
    5.     android:layout_height="match_parent"
    6.     android:paddingBottom="@dimen/activity_vertical_margin"
    7.     android:paddingLeft="@dimen/activity_horizontal_margin"
    8.     android:paddingRight="@dimen/activity_horizontal_margin"
    9.     android:paddingTop="@dimen/activity_vertical_margin"
    10.     tools:context="com.example.ivan.fragmentsgameplay.MainActivity">
    12.     <TextView
    13.         android:layout_width="wrap_content"
    14.         android:layout_height="wrap_content"
    15.         android:text="Hello World!" />
    17.     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    18.         android:orientation="vertical"
    19.         android:layout_width="match_parent"
    20.         android:layout_height="match_parent">
    21.         <fragment android:name="com.example.ivan.fragmentsgameplay.FragmentOne"
    22.             android:id="@+id/list"
    23.             android:layout_weight="1"
    24.             android:layout_width="match_parent"
    25.             android:layout_height="0dp" />
    26.         <fragment android:name="com.example.ivan.fragmentsgameplay.FragmentTwo"
    27.             android:id="@+id/viewer"
    28.             android:layout_weight="2"
    29.             android:layout_width="match_parent"
    30.             android:layout_height="0dp" />
    31.     </LinearLayout>
    32. </RelativeLayout>

    As you can see there are two fragments that are placed with 1/3 to 2/3 ratio one above the other.

    The problem is when I work separately on, say: fragmentOne.xml file (via Design bar in Android Studio. )
    It shows me that this layout actually fills up all the screen space.
    So as far as can understand the final output layout will be dictated by main_activity.xml and all the great stuff that I would add to fragmentOne.xml will be resized in order to fit onto screen.

    My question is about fragmentOne.xml (and fragmentTwo.xml too ^_^) is there some good way to define its dimensions so they initially suit those defined in main_activity.xml?

    I mean in such case I'll work within a dimensions that will be actually presented to user, and will place all the elements(inside fragmentOne.xml file) in a proper way.

    Without having a headache of rearranging those elements afterwards due to re-sizing of main_activity.xml.

    An example of my fragmentOne.xml file:

    Code (Java):
    1. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    2.     xmlns:tools="http://schemas.android.com/tools"
    3.     android:layout_width="match_parent"
    4.     android:layout_height="match_parent"
    5.     tools:context="com.example.ivan.fragmentsgameplay.FragmentOne"
    6.     android:background="#323b8a">
    8.     <!-- TODO: Update blank fragment layout -->
    10.     <Button
    11.         android:layout_width="wrap_content"
    12.         android:layout_height="wrap_content"
    13.         android:id="@+id/frag_one_button"
    14.         android:layout_gravity="center_horizontal|top"
    15.         android:textAllCaps="true"
    16.         android:text="Go To Fragment Two" />
    17. </FrameLayout>

    Thanks a lot for help. (hope my question was clear ^_^, and yes I'm an Android newbie)


Share This Page